怎么清除html中的文本,清除文本中Html的标签

///

/// 清除文本中Html的标签

///

///

///

protected string ClearHtml(string Content)

{

Content = ReplaceHtml("[^>]*;", "", Content);

Content = ReplaceHtml("?marquee[^>]*>", "", Content);

Content = ReplaceHtml("?object[^>]*>", "", Content);

Content = ReplaceHtml("?param[^>]*>", "", Content);

Content = ReplaceHtml("?embed[^>]*>", "", Content);

Content = ReplaceHtml("?table[^>]*>", "", Content);

Content = ReplaceHtml(" ", "", Content);

Content = ReplaceHtml("?tr[^>]*>", "", Content);

Content = ReplaceHtml("?th[^>]*>", "", Content);

Content = ReplaceHtml("?p[^>]*>", "", Content);

Content = ReplaceHtml("?a[^>]*>", "", Content);

Content = ReplaceHtml("?img[^>]*>", "", Content);

Content = ReplaceHtml("?tbody[^>]*>", "", Content);

Content = ReplaceHtml("?li[^>]*>", "", Content);

Content = ReplaceHtml("?span[^>]*>", "", Content);

Content = ReplaceHtml("?div[^>]*>", "", Content);

Content = ReplaceHtml("?th[^>]*>", "", Content);

Content = ReplaceHtml("?td[^>]*>", "", Content);

Content = ReplaceHtml("?script[^>]*>", "", Content);

Content = ReplaceHtml("(javascript|jscript|vbscript|vbs):", "", Content);

Content = ReplaceHtml("on(mouse|exit|error|click|key)", "", Content);

Content = ReplaceHtml("]*>", "", Content);

Content = ReplaceHtml("]*>", "", Content);

Content = ReplaceHtml("?font[^>]*>", "", Content);

Content = ReplaceHtml("?b[^>]*>", "", Content);

Content = ReplaceHtml("?u[^>]*>", "", Content);

Content = ReplaceHtml("?i[^>]*>", "", Content);

Content = ReplaceHtml("?strong[^>]*>", "", Content);

string clearHtml = Content;

return clearHtml;

}

///

/// 清除文本中的Html标签

///

/// 要替换的标签正则表达式

/// 替换为的内容

/// 要替换的内容

///

private string ReplaceHtml(string patrn, string strRep, string content)

{

if (string.IsNullOrEmpty(content))

{

content = "";

}

Regex rgEx = new Regex(patrn, RegexOptions.IgnoreCase);

string strTxt = rgEx.Replace(content, strRep);

return strTxt;

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值