Editing a txt file
Posted on 2005-04-28
Hello guys & gals,
I have an ini file which I need to modify.
One of the way I know is to read the file using StreamReader, then modify the string you read it in, and then write it back using StreamWriter.
I only need to find two words on two lines in the text, which will be on the different lines but might not be separated with spaces or anything, like dirbase=blah-blah-blah. If I find this stuff in my file, I just need to comment this two lines out using # character, like
// if it was
dirbase = c:\blah-blah-blah
// it will be
#dirbase = c:\blah-blah-blah
Do I really need to read aaaaall file and do it all in the string? Is there any way to do someting like:
Read line by line,
If line is found, modify the line - e.g. Write back the line