PDA

View Full Version : Reading of a Particular line & replacing its text after particular character



Pardeep
12th October 2012, 16:45
Hello Everyone,

I have an application in which i want to create file to store some string from different location.
(Say)
"stylesheetfile: abc.txt" from a function & "Languagefile: xyz.txt" form another function.

If Particular line not present if file then store that line, otherwise, read that line & based on Languagefile:/stylesheetfile: replace rest of line.

Thanks in Advance for your valuable help.

Regards
Pardeep Sharma

wysota
12th October 2012, 21:32
It is not possible to "replace" a line in file (unless the replacement has exactly the same number of bytes as the part being replaced) and neither it is possible to "insert" a line in the middle of a file. If you need something like this, you have to rewrite every successive byte of the file. So it's usually easier to just read the file to memory, modify it there and then write everything back.