using (StreamReader sr = new StreamReader(@"E:\TestArtile.txt",Encoding.UTF8))
{
string artileContent = sr.ReadToEnd();
sr.Close();
Perfect.Base.Report.Reporter.Info(artileContent);
artileContent = Regex.Replace(artileContent, "(\r|\n|\r\n)+", "\r\n");
MatchCollection paragraphs = Regex.Matches(artileContent, @"[\s\S]+?(\r\n|$)+");
//到这已经取得了文章段落
//paragraphs[0]为第一段
//paragraphs[1]为第二段
//..下面的代码只是为了测试分段是否正确而写的
StringBuilder result = new StringBuilder();
for (int i = 0, j = paragraphs.Count; i < j; i++)
{
result.Append("第" + (i + 1) + "段内容:" + paragraphs[i]);
result.Append("\r\n\r\n\r\n");
}
FileInfo fi = new FileInfo(@"E:\TestArtileResult.txt");
using (FileStream fs = fi.OpenWrite())
{
StreamWriter sw = new StreamWriter(fs, Encoding.UTF8);
sw.Write(result.ToString());
sw.Flush();
sw.Close();
}
}
温馨提示:答案为网友推荐,仅供参考