Sorting incoming text data file in C# by a range of the record -
i have file coming in (for display in textbox).
var lines = new [] { "123465.xxx.20150115", "123465.xxx.20150222", "999999.xxx.20150120", };
i can't affect sorted order receive in. however, want sort column 12 column 19, column 1 thru 6 (by date number) - in reverse order.
currently call dos sort (.bat) on file creating new file, there has way sort in c#.
i want sort in textbox or load array, sort it, load textbox.
try this:
var lines = new [] { "123465.xxx.20150115", "123465.xxx.20150222", "999999.xxx.20150120", }; var sorted = lines .orderbydescending(l => l.substring(11, 8) + l.substring(0, 6)) .toarray();
since string indexing 0
-based .substring(11, 8)
gives "column 12 column 19" & .substring(0, 6)
gives "column 1 thru 6".
i result:
Comments
Post a Comment