6
Answers

Find text, in .txt file, replace with nothing (remove line)

Ask a question
thiago costa

thiago costa

11y
2.3k
1
Hello there guys...

I have a text file called online.txt.

each time the program executes, it will append a new line of text. works 100%.

Now, what I am trying to acomplish, is: Everytime the program closes I want to replace _user with an empty line.

When I say empty line, I mean the line doesn't exist...


I tryed this: Doesnt work.

try
            {
                this.EndInvoke(this.BeginInvoke(new MethodInvoker(delegate()
            {
                String strxFile = File.ReadAllText("online.txt");

                strxFile = strxFile.Replace(_user, null);

                File.WriteAllText("online.txt", strxFile);
            })));
            }
            catch
            { }

I tryed this too:                 strxFile = strxFile.Replace(_user, "");

Doesnt work... both commands above will leave the line existing, with no string in it..

The real story is, I want to delete the line 100% like the line is not there.



Thanks Guys.

Answers (6)