我已经从一个匹配的文件中读取并写入另一个匹配一个数字的次数。如何删除每个号码并只为该号码留下一条记录。我的意思是现在我得到:
Count of matching numbers in this group: 123
Numbers:
...123 times this number i.e 123 lines.
如何删除这个号码并这样写:
Count of matching numbers in this group: 123
Number: the number
这就是我现在的做法:
string path = "file1.txt";
var result = (File.ReadLines(path)).OrderBy(x => x).GroupBy(x => x);
using (var writer = new StreamWriter("file2.txt"))
{
foreach (var item in result)
{
string outGrp = String.Format("Count of matching numbers in this group: {0}", item.Count());
Console.WriteLine(outGrp);
writer.WriteLine(outGrp, true);
Console.WriteLine("Numbers:");
writer.WriteLine("Numbers:", true);
foreach (var member in item)
{
Console.WriteLine(member);
writer.WriteLine(member, true);
}
}
}