文本文件分隔-性能问题
本文关键字:性能 问题 分隔 文件 文本 | 更新日期: 2023-09-27 18:21:17
我有一个文本文件,详细信息如下,没有标题
Name1 Text1 This is the message1
Name2 Text2 This is the message2
如果我这样使用。。
string[] allLines = File.ReadAllLines("TextFile.log");
for (int i = 0; i < allLines.Length; i++
{
string[] items = allLines[i].Split(new char[] { ' ' });
MessageBox.Show("This is Name field : " + items[0])
MessageBox.Show("This is Text field : " + items[1])
MessageBox.Show("This is Message field : " + items[2])
}
如果我使用上面的代码,它将适用于前两个字段,但如何在单列中获得第三列"This is the message1"?
使用Split
方法的适当重载进行拆分时,只需指定最多需要3个项目:
string[] items = allLines[i].Split(new char[] { ' ' }, 3);