去掉 HTML 标签?
如何剥离此文本,
<html>
<body>
<h1>My First Heading</h1>
<p>My first paragraph.</p>
<[email protected]>
</body>
</html>
使其看起来像
My First Heading
My first paragraph.
<[email protected]>
功能
public static string StripHTML(this string htmlText)
{
var reg = new Regex("<(.|\n)*?>", RegexOptions.IgnoreCase);
return reg.Replace(htmlText, "");
}
使用“我得到
我的第一个标题” 我的第一段。
How to strip this text
<html>
<body>
<h1>My First Heading</h1>
<p>My first paragraph.</p>
<[email protected]>
</body>
</html>
to look like
My First Heading
My first paragraph.
<[email protected]>
Using the function
public static string StripHTML(this string htmlText)
{
var reg = new Regex("<(.|\n)*?>", RegexOptions.IgnoreCase);
return reg.Replace(htmlText, "");
}
I get
My First Heading
My first paragraph.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用 Html Agility Pack 进行此类操作。它比任何正则表达式都快并且支持 LINQ。
Use Html Agility Pack for these kinds of operations. It is faster than any regex and supports LINQ.