我想通過html div標記分割文章的正文,所以我有一個模式來搜索div。 的問題是,該圖案也分割\ r \ n [此處輸入圖像的描述] [1]爲什麼正則表達式分割添加到模式 r n
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解釋問題
你在一個可以向我們展示導致此問題的身體字符串的示例嗎? –