在.NET中获取的纯文本从HTML [英] Get plain text from HTML in .NET
本文介绍了在.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)*?>", "");
这篇关于在.NET中获取的纯文本从HTML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文