HTMLagilitypack不会删除所有html标签如何有效解决此问题? [英] HTMLagilitypack is not removing all html tags How can I solve this efficiently?
本文介绍了HTMLagilitypack不会删除所有html标签如何有效解决此问题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用以下方法从字符串中删除所有html:
I am using following method to strip all html from the string:
public static string StripHtmlTags(string html)
{
if (String.IsNullOrEmpty(html)) return "";
HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument();
doc.LoadHtml(html);
return doc.DocumentNode.InnerText;
}
但是似乎忽略了以下标记:[…]
But it seems ignoring this following tag: […]
因此该字符串基本上返回:
So the string returns basicly:
> 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 […]
如何确保剥离此类标签?
How can I make sure that these kind of tags gets stripped?
感谢任何帮助,谢谢.
推荐答案
尝试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将[…]
转换为[…]
HtmlDecode will convert […]
to […]
这篇关于HTMLagilitypack不会删除所有html标签如何有效解决此问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文