I need to pull data from a text file, sort it, then save over the old data with the newly sorted data. Here is the format of the text file:
Dog
Cow
Sheep
If I read the text into an list, then call the sort method, I get this:
""
""
""
Cow
Dog
Sheep
That’s not what I want. Is there a way for .Sort() to ignore white spaces, or should I approach this problem differently?
EDIT I need the empty lines to be there when I save back to the file. The output should be
Cow
Dog
Sheep
Use Linq. Following should work: