how to delete first line in a txt file
-
i am new in c#. I want to delete the first line in the txt file .
-
Answer:
Basically you need to copy it to another file - you can't remove (or insert) data in a file "in place". For example, in .NET 4 it's easy: var lines = File.ReadLines("input.txt").Skip(1); File.WriteAllLines("output.txt", lines); It's slightly more work in older versions of .NET, at least if you want to avoid loading the whole file into memory, but still not too hard. Let me know if you need the code for an older version (and state which). EDIT: As discussed in comments, if you're willing to load the whole file into memory, you can write straight back to the same file: // Note that ReadAllLines is eager, not lazy like ReadLines var lines = File.ReadAllLines("file.txt").Skip(1); File.WriteAllLines("file.txt", lines);
Arshiya Gm at Stack Overflow Visit the source
Related Q & A:
- How convert .txt file to .Dat file in php?Best solution by Stack Overflow
- How to extract frequency range from a Wav file?Best solution by Stack Overflow
- How to delete a line from a .txt file in node.js?Best solution by c-sharpcorner.com
- How to delete an entry from a dictionary in Python?Best solution by Stack Overflow
- How is .txt file different from a .dat file in C?Best solution by mycplus.com
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.