【问题标题】:How to remove html tags from text using c# [duplicate]如何使用c#从文本中删除html标签[重复]
【发布时间】:2014-11-26 07:18:12
【问题描述】:

我有这样的字符串

<p>There was a <b>.NET</b> programmer and he stripped the <i>HTML</i> tags.</p><br> </br>

如何从给定的字符串中删除那些 html 标签

【问题讨论】:

标签: c#


【解决方案1】:

使用Htmlagilitypack

var document = new HtmlDocument();
document.LoadHtml(data);
string text= document.DocumentNode.InnerText;

【讨论】:

  • 感谢它的工作感谢 rjv......
【解决方案2】:

你可以使用 Regex.Replace 这样的事情就可以了

var input = "<p>There was a <b>.NET</b> programmer and he stripped the <i>HTML</i> tags.</p><br> </br>";
var filtered = System.Text.RegularExpressions.Regex.Replace(input, "<.*?>", "");
Console.WriteLine(filtered);

【讨论】:

    猜你喜欢
    • 2016-04-06
    • 2010-11-10
    • 2012-12-06
    • 2012-12-29
    • 2015-12-16
    • 1970-01-01
    • 1970-01-01
    • 2011-09-04
    • 2019-05-01
    相关资源
    最近更新 更多