我有一个文本文件,其详细信息如下,没有标题
Name1 Text1 This is the message1
Name2 Text2 This is the message2
Run Code Online (Sandbox Code Playgroud)
如果我这样使用..
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])
}
Run Code Online (Sandbox Code Playgroud)
如果我使用上面的代码,它将适用于前2个字段,但如何在单列中获得第三列"This is the message1"?
使用方法的适当重载分割时,只需指定最多需要3个项目Split:
string[] items = allLines[i].Split(new char[] { ' ' }, 3);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
54 次 |
| 最近记录: |