Quantcast
Channel: Windows Forms General forum
Viewing all articles
Browse latest Browse all 12583

I want to sort data from a tsv file using C# console. I can get the data to display but cannot sort it using the second column

$
0
0

Sorting the first column is fairly easy but I cannot get it to sort by the second one, please suggest the steps for completing the program, any help is greatly appreciated.

heres my code so far:

  string[] lines = File.ReadAllLines(@"d:\data\542112107\Desktop\project 1\Project1\Project1\bin\Debug\instance_test.txt");
            //Dictionary<String, Int32> EAR_appcode = new Dictionary<String, Int32>();
            //Console.WriteLine();
            //Console.ReadLine();
            //// Display the file contents by using a foreach loop.
            //System.Console.WriteLine("Contents of WriteLines2.txt = ");
            //foreach (string line in lines)
            //{
            //    // Use a tab to indent each line of the file.
            //    Console.WriteLine("\t" + line.Substring(4));
            //    Console.ReadLine();
            //}
            var no = lines;
            var orderedScores = lines.OrderBy(x => x.Split('9')[0]);
            //string result = Regex.Split(no, @"[,\t ]+");
            foreach (var score in orderedScores)
            {
                string replacement = Regex.Replace(score, @"\t|\n|\r", "           ");
                Console.WriteLine(replacement);
                Console.ReadLine();

            }
            // Keep the console window open in debug mode.
            Console.WriteLine("Press any key to exit.");
            System.Console.ReadKey();


Viewing all articles
Browse latest Browse all 12583

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>