|
-
April 22nd, 2006, 02:21 PM
#1
delete a line in a file
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
-
April 22nd, 2006, 04:52 PM
#2
Re: delete a line in a file
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();
}
-
April 22nd, 2006, 05:21 PM
#3
Re: delete a line in a file
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|