blah blah blah is here! blah blah » Close
hi i have a text file with 1000 lines and i wand to delete the last line each time i press a button! is any function to delete the last line??thanks
Could you post your existing code?
since they are 1000 lines "which is not that high unless the line has many bytes", read all the lines and write them without the last line.
string myfile="C:\myFile.txt";//any file name System.Collections.Generic.List<string> newLines = new System.Collections.Generic.List<string>(); newLines.AddRange(System.IO.File.ReadAllLines(myfile)); newLines.RemoveAt(newLines.Count - 1); System.IO.File.WriteAllLines(myfile, newLines.ToArray());
answered 2 years ago by:
yes but the file have 1000 for start and i beleve the max lines will be 6000-8000
You can improve performance by only writing back the remaining lines to the file when the application is about to close.
and if the application dont close correctly, then the file is brocken???
Got feedack? Found a bug? report it here.
1 answers
since they are 1000 lines "which is not that high unless the line has many bytes", read all the lines and write them without the last line.
answered 2 years ago by:
1556
30
yes but the file have 1000 for start and i beleve the max lines will be 6000-8000
17279
You can improve performance by only writing back the remaining lines to the file when the application is about to close.
30
and if the application dont close correctly, then the file is brocken???