如何获取文件的一部分并将这些行写入C#中的数组

时间:2018-10-28 01:50:23

标签: c#

如果我有一个文件读取:

SECTION_00

*几行数据

SECTION_01

*几行数据

我想从SECTION_00行开始,并将该行及其下的所有行写到一个行数组中,直到到达SECTION_01。然后将SECTION_01再次做同样的事情,放入另一个数组中。

1 个答案:

答案 0 :(得分:0)

string filePath = "Path";
string content = File.ReadAllText(filePath);
string[] sections = content.Split(new string[] {"SECTION_00", "SECTION_01"});

string section00 = sections[0];
string section01 = sections[1];

在Split()字符串数组中添加更多部分