tags:

views:

55

answers:

2

How to sort comma separated values in file comparing only first element in each row.

+1  A: 

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)

marcind
Please do not post code for obvious homework questions. That's not helpful. Rather point in the right direction.
EricSchaefer
You're right, I could have taken either the Socratic or the Zen Master approach, but this was easier ;)
marcind
;-) But it was also easier for Sap. Too easy. He will not learn this way...
EricSchaefer
+2  A: 
  • Read the file line by line
  • Split the lines at the commas
  • Sort
  • Write back to file
EricSchaefer