【发布时间】:2023-04-01 07:31:01
【问题描述】:
我想用 html div 标签分割文章的正文,所以我有一个搜索 div 的模式。 问题是模式也分裂了 \r\n [在此处输入图片说明][1]
string pattern = @"<div[^<>]*>(.*?)</div>";
string[] bodyParagraphsnew = Regex.Split(body, pattern,RegexOptions.None);
Response.Write("num of paragraph =" + bodyParagraphsnew.Length);
for (int i = 0; i < bodyParagraphsnew.Length; i++)
{
Response.Write("bodyParagraphs" + i + "= " + bodyParagraphsnew[i]+ Environment.NewLine);
}
当我调试这段代码时,我在数组 bodyParagraphsnew 中看到很多“\r\n”。
可以看出该模式包括由字符串“\r\n”分割 我尝试将 \r\n 替换为空字符串,我希望 bodyParagraphsnew 长度会改变。但不是。我得到的不是包含 \r\n 它包含“”的项目(在数组中) 为什么?
这里是图片http://i.stack.imgur.com/Hxqki.gif 的链接,用于解释问题
【问题讨论】:
-
您能否向我们展示导致此问题的正文字符串示例?