我使用以下方法從字符串中刪除所有html:
public static string StripHtmlTags(string html)
{
if (String.IsNullOrEmpty(html)) return "";
HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument();
doc.LoadHtml(html);
return doc.DocumentNode.InnerText;
}
但它似乎忽略了以下標籤: […]
所以字符串基本返回:
> A hungry thief who stole a rack of pork ribs from a grocery store has
> been sentenced to spend 50 years in prison. Willie Smith Ward felt the
> full force of the law after being convicted of the crime in Waco,
> Texas, on Wednesday. The 43-year-old may feel slightly aggrieved over
> the severity of the […]
如何確保剝離這些標籤?
任何形式的幫助表示讚賞,謝謝。
試試HttpUtility.HtmlDecode
public static string StripHtmlTags(string html)
{
if (String.IsNullOrEmpty(html)) return "";
HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument();
doc.LoadHtml(html);
return HttpUtility.HtmlDecode(doc.DocumentNode.InnerText);
}
HtmlDecode會將[…]
轉換為[…]