Hello to evreyone i am using Visual Studio 2008 for native program project.
I am using StreamReader and StreamWriter to read and write to file my question is, how can i replace a line with new value without change line.
e.g myfile.txt
blue
red
yellow
and to change to
green
red
yellow
The value is not the same but i want to replace and not to delete and writer new because is organized by ID!
Thank you
1 reply to this topic
#1
Posted 14 August 2011 - 12:15 AM
|
|
|
#2
Posted 18 August 2011 - 09:15 AM
First you need to read the contents of the file line by line. Then if it contains a certain text replace it with your new text.
The above code is obviously not a working example but I hope you get the point. :)
~ Committed.
ReadFileByLine
If Line.Contains("Blue")
Line = Line.Replace("Blue", "Green")
The above code is obviously not a working example but I hope you get the point. :)
~ Committed.
A man can be defined by what he does when no one is looking.
Science is only an educated theory, which we cannot disprove.
Science is only an educated theory, which we cannot disprove.
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users


Sign In
Create Account

Back to top









