我有下一个文件:timesBetweenStartToEnd.txt
其中包含:
Starting at: 12:15:28 -> Ending at: 12:17:38 -> 130 Seconds
Starting at: 12:12:18 -> Ending at: 12:12:38 -> 20 Seconds
.....
我想按秒数对其进行排序,并将排序后的行插入另一个名为:logTimes.txt
.
我尝试了下一件事:
string[] scores = System.IO.File.ReadAllLines("timesBetweenStartToEnd.txt");
var orderedScores = scores.OrderByDescending(x => int.Parse(x.Split(' ')[8]
.Substring(0,scores.IndexOf(" "))); // here I have an error because of `scores.`, I neead an index
foreach (var score in orderedScores)
{
System.IO.File.AppendAllText(@"logTimes.txt", string.Format("{0}{1}", orderedScores, Environment.NewLine));
}
所以,logTimes.txt
应该包含(降序):
Starting at: 12:15:28 -> Ending at: 12:17:38 -> 130 Seconds
Starting at: 12:12:18 -> Ending at: 12:12:38 -> 20 Seconds
任何帮助表示赞赏!