简体   繁体   English

如何使用 3 个空行作为分隔符拆分文本文件?

[英]How do I split text file using 3 empty lines as a delimiter?

My text file:我的文本文件:

TestTest
testtest
testtest



testtesttest
testtesttest
testtestset



testtsetse



testestset

I know how to split it with 1 empty line as a delimiter:我知道如何用 1 个空行作为分隔符分割它:

string file = File.ReadAllText(filePath)

string[] files = file.Split('\n');

When I use the next code it gives an error cannot convert from string to char :当我使用下一个代码时,它给出了一个错误cannot convert from string to char

string[] files = file.Split("\n\n\n");

But when I try:但是当我尝试:

string[] files = file.Split("\n\n\n".ToCharArray());

it's not working.它不工作。

Any ideas?有任何想法吗?

string[] files = file.Split(Environment.NewLine + Environment.NewLine + Environment.NewLine, StringSplitOptions.RemoveEmptyEntries);

You can read file line by line您可以逐行读取文件

string line;  
   
System.IO.StreamReader file = new System.IO.StreamReader(filePath);  
while((line = file.ReadLine()) != null)  
{  
    System.Console.WriteLine(line);  
}  
  
file.Close();  

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM