I'm doing a little program where the data saved on some users are stored in a text file. I'm using Sytem.IO
with the Streamwriter
to write new information to my text file.
The text in the file is formatted like so :
name1, 1000, 387
name2, 2500, 144
... and so on. I'm using infos = line.Split(',')
to return the different values into an array that is more useful for searching purposes. What I'm doing is using a While
loop to search for the correct line (where the name match) and I return the number of points by using infos[1]
.
I'd like to modify this infos[1]
value and set it to something else. I'm trying to find a way to replace a word in C# but I can't find a good way to do it. From what I've read there is no way to replace a single word, you have to rewrite the complete file.
Is there a way to delete a line completely, so that I could rewrite it at the end of the text file and not have to worried about it being duplicated?
I tried using the Replace
keyword, but it didn't work. I'm a bit lost by looking at the answers proposed for similar problems, so I would really appreciate if someone could explain me what my options are.