I am attempting to sort xls lines by fourth string in lines.
string[] list_lines = System.IO.File.ReadAllLines(@"E:\VS\WriteLines.xls");
// Display the file contents by using a foreach loop.
System.Console.WriteLine("Contents of Your Database = ");
foreach (var line in list_lines)
{
// Use a tab to indent each line of the file.
Console.WriteLine("\t" + line);
}
I am having problems creating algorithm that will identify the fourth element of each line and list content in alphabetical order. The words in each line are separated by ' '.
Can anyone put me on a right direction please?
EDIT-------------------------- ok,
foreach (var line in list_lines.OrderBy(line => line.Split(' ')[3]))
sorted the problem. Lines are sorted as I need. Excel changes ' ' spaces with ';'. That's why when compiled it was giving error.
Now, I guess, I need to parse each part of string to int since it sorts by first digit and not by a number.