在.NET中获取的纯文本从HTML
问题描述:
什么是得到一个HTML字符串的纯文本字符串,最好的方法是什么?
What is the best way to get a plain text string from an HTML string?
public string GetPlainText(string htmlString)
{
// any .NET built in utility?
}
在此先感谢
答
有没有内置的实用工具,据我所知,但根据您的要求,您可以使用普通防爆pressions剥离所有的标签:
There's no built in utility as far as I know, but depending on your requirements you could use Regular Expressions to strip out all of the tags:
string htmlString = @"<p>I'm HTML!</p>";
Regex.Replace(htmlString, @"<(.|\n)*?>", "");