Opening a notepad file and editing text
I have some txt files, which having some text in that. My requirement is:
1. Open the first file and extract from 6 to 18 characters from the first line(always same line)and replace it with some other text.
2. do the same thing for all the txt files
3. But the source string will be different to different txt file.
Where iam stuck up:
If I open the file in write mode, it is clearing the entire text.
If I open the file in Append mode, it will append at end of the file.
1. Open the file(not clear in which mode to open)
3. take the substring(6,18)
5. Dont know how to replace a string with other
can you please suggest me in this??
Re: Opening a notepad file and editing text
There are 2 issues for which you need a solution:
1. How to replace a part of a string?
2. How to modify lines in a file?
ad 1. A string-replacement-function will consist of the functions index (or match), length and substr. I guess if you search through this forum, this function may have been posted a longer time ago.
ad 2. There is no function for reading & writing a file at once. You will have to read the file first and then write (the modified file) again. You can do this by storing the lines of the file in an array (if the file is not too big), or you can write a 2nd file while reading the first file line by line, and then replace the first file by the 2nd file (e.g. by using dos_system and some DOS-commands).