タブ区切りのtxtファイルから3列目を使用してデータをソートしようとしています。いくつかの方法を試しましたが、3 番目の列を使用して並べ替える方法がわかりません。今のところ最初のものを使用してソートしました。また、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();
}