开发者

Sort CSV comparing only first element in each row

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)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜