我正在尝试使用制表符分隔的 txt 文件中的第三列对数据进行排序。尝试了几种方法,不确定我如何使用第三列对其进行排序。目前已经使用第一个对其进行了排序。此外,我需要从第 3 列中删除重复项(区分大小写,即 river 与 River 不同)这是我的代码。一旦我取得进展,将标记为答案。谢谢 ;)
string[] lines = File.ReadAllLines(@"d:\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(' ')[0]);
//string result = Regex.Split(no, @"[,\t ]+");
foreach (var score in orderedScores)
{
string replacement = Regex.Replace(score, @"\t|\n|\r", " ");
DataTable table = new DataTable();
table.Columns.Add("myCol", typeof(string));
table.Columns.Add("myCol2", typeof(string));
table.Columns.Add("EAR_appcode", typeof(string));
table.Rows.Add(11, "abc11");
table.Rows.Add(13, "abc13");
table.Rows.Add(12, "abc12");
Console.WriteLine(replacement) ;
Console.ReadLine();
}
// Keep the console window open in debug mode.
Console.WriteLine("Press any key to exit.");
System.Console.ReadKey();
}