How do you sort comma separated values in a file by compa开发者_运维技巧ring only first element in each row?
- Read the file line by line
- Split the lines at the commas
- Sort
- Write back to file
Something like:
var result = File.ReadAllLines(pathToFile).OrderBy(line => line.Split(",")[0])
Just note that this assumes your input is always valid. You would have to add your own error checking (empty rows, empty files, etc)
精彩评论