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
2010-07-21 05:36:11
Please do not post code for obvious homework questions. That's not helpful. Rather point in the right direction.
EricSchaefer
2010-07-21 05:38:38
You're right, I could have taken either the Socratic or the Zen Master approach, but this was easier ;)
marcind
2010-07-21 05:44:31
;-) But it was also easier for Sap. Too easy. He will not learn this way...
EricSchaefer
2010-07-21 07:47:24
+2
A:
- Read the file line by line
- Split the lines at the commas
- Sort
- Write back to file
EricSchaefer
2010-07-21 05:37:25