我有这样的文字分析文本,并保存在内存中的C#
5 1 5 1 5 1 5 1
1
我得
5 1 5 1 5 1 5 1
0 1 0 0 0 0 0 0
,并将其保存在内存中。但是,当我使用这样的建设:
List<string> lines=File.ReadLines(fileName);
foreach (string line in lines)
{
var words = line.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
foreach(string w in words)
Console.Write("{0,6}", w);
// filling out
for (int i = words.Length; i < 8; i++)
Console.Write("{0,6}", "0.");
Console.WriteLine();
}
我只打印所需的格式显示文本。 如何将它保存在List<string> newLines
?
所以你想保存你的输出,因为它是在字符串列表中? – Shaharyar 2013-03-26 08:12:05
如果你使用'RemoveEmptyEntries',你怎么知道第二行'1'的位置是?坦率地说,解析,我根本不认为'Split'是正确的选择 – 2013-03-26 08:12:17
我没有把答案作为不确定,如果它是你想要的,而是(或者)'Console.Write',你可以使用'newLines.Add(string)' – Sayse 2013-03-26 08:12:27