Hello, do you know how can i delete a specific line in a text? Is there a specific command? Is it possible not lo leave the line blank and bring the next records one place up?
Thanksssss
Printable View
Hello, do you know how can i delete a specific line in a text? Is there a specific command? Is it possible not lo leave the line blank and bring the next records one place up?
Thanksssss
I don't know if that's an already available command...but a function that will do it is:
Code:public static void DeleteLine(String file, int line)
{
StreamReader streamIn = new StreamReader(file);
String newFile = "";
for (int i = 0; i < line && !streamIn.EndOfStream; i++)
{
newFile += streamIn.ReadLine();
newFile += "\r\n";
}
streamIn.ReadLine();
newFile += streamIn.ReadToEnd();
streamIn.Close();
StreamWriter streamOut = new StreamWriter(file);
streamOut(newFile);
streamOut.Flush();
}
Even better you should read the file into an ArrayList of strings per line, remove the line you want and write it out again.
Darwen.