我有這樣的文字分析文本,並保存在內存中的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