私はC#にはかなり新しいですが、私はこの問題を解決できません(おそらく単純なものです)。c#文字列のリスト> sort by regex?
エラーログの文字列を含む2つのリストがあります。 (それは文字列の配列を使用することをお勧めします場合は、私に教えてください)
/* Example of list from host 1
2017-06-29 02:25:54.309 BST,ERROR,.......
2017-06-29 02:25:54.357 BST,ERROR,.......
2017-06-29 02:25:54.495 BST,ERROR,.......
2017-06-29 02:30:57.183 BST,ERROR,.......
2017-06-29 03:07:12.078 BST,ERROR,.......
2017-06-29 05:07:13.256 BST,ERROR,.......
2017-06-29 05:14:14.717 BST,ERROR,.......
2017-06-29 05:16:23.954 BST,ERROR,.......
2017-06-29 08:12:16.418 BST,ERROR,.......
2017-06-29 08:37:23.574 BST,ERROR,.......
2017-06-29 09:07:11.569 BST,ERROR,....... */
List<string> filteredLogFileC1 = filterLog(hostNameC1); //filterLog returns a List<string>
/* Example of list from host 2
2017-06-29 00:43:43.781 BST,ERROR,.......
2017-06-29 00:43:44.446 BST,ERROR,.......
2017-06-29 00:43:44.885 BST,ERROR,.......
2017-06-29 00:43:45.378 BST,ERROR,.......
2017-06-29 00:43:45.940 BST,ERROR,.......
2017-06-29 00:43:46.584 BST,ERROR,.......
2017-06-29 00:43:47.141 BST,ERROR,....... */
List<string> filteredLogFileC2 = filterLog(hostNameC2); //filterLog returns a List<string>
// Combine the 2 lists into one (the below practice might not be the best one but its working and I am happy at the moment :))
/*
... Combined list
2017-06-29 08:12:16.418 BST,ERROR,.......
2017-06-29 08:37:23.574 BST,ERROR,.......
2017-06-29 09:07:11.569 BST,ERROR,.......
2017-06-29 00:43:43.781 BST,ERROR,.......
2017-06-29 00:43:44.446 BST,ERROR,.......
2017-06-29 00:43:44.885 BST,ERROR,.......
...
*/
foreach (string line in filteredLogFileC2) filteredLogFileC1.Add(line);
// I need to sort the filteredLogFileC1 list by date.
// Below I have a regex that I've put together but I don't know how I can use it
Regex sortReg = new Regex(@"(\d{4}-\d{2}-\d{2}) (\d{2}:\d{2}:\d{2}.\d{3})");
Issue: filteredLogFileC1.OrderBy(???sortReg???)
は、ご提案をいただき、ありがとうございます。
で最初のものに2つ目のリストを追加するには '.AddRange'の方法があります。 –
「正規表現による並べ替え」とはどういう意味ですか?最終結果はどうなりますか? –
あなたの日付が常に同じ形式(そして常に年からミリ秒の順序)であれば、アルファベットの標準的な並べ替えを使用できるはずです。 –