thiago costa

thiago costa

  • NA
  • 319
  • 0

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

Jul 2 2013 9:10 AM
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)