广告载入中
  所在位置:网站首页 -> 网络学院 -> .NET -> ASP.NET -> ASP.NET清除HTML标记函数
我要发言 发起投票 发起交易 任务悬赏 回复话题              

ASP.NET清除HTML标记函数

时间:2007-12-4 21:08:10 作者: NO2 短消息 收藏 编辑 删除
广告载入中
广告载入中
广告载入中
实际需要写的一个ASP.NET清除HTML标记的函数,给大家一起学习一下,整理发布,
//清除HTML函数
public static string NoHTML(string Htmlstring)
{

//删除脚本

Htmlstring = Regex.Replace(Htmlstring, @"<script[^>]*?>.*?</script>", "", RegexOptions.IgnoreCase);

//删除HTML

Htmlstring = Regex.Replace(Htmlstring, @"<(.[^>]*)>", "", RegexOptions.IgnoreCase);

Htmlstring = Regex.Replace(Htmlstring, @"([\r\n])[\s] ", "", RegexOptions.IgnoreCase);

Htmlstring = Regex.Replace(Htmlstring, @"-->", "", RegexOptions.IgnoreCase);

Htmlstring = Regex.Replace(Htmlstring, @"<!--.*", "", RegexOptions.IgnoreCase);



Htmlstring = Regex.Replace(Htmlstring, @"&(quot|#34);", "\"", RegexOptions.IgnoreCase);

Htmlstring = Regex.Replace(Htmlstring, @"&(amp|#38);", "&", RegexOptions.IgnoreCase);



Htmlstring = Regex.Replace(Htmlstring, @"&(lt|#60);", "<", RegexOptions.IgnoreCase);

Htmlstring = Regex.Replace(Htmlstring, @"&(gt|#62);", ">", RegexOptions.IgnoreCase);

Htmlstring = Regex.Replace(Htmlstring, @"&(nbsp|#160);", " ", RegexOptions.IgnoreCase);

Htmlstring = Regex.Replace(Htmlstring, @"&(iexcl|#161);", "\xa1", RegexOptions.IgnoreCase);

Htmlstring = Regex.Replace(Htmlstring, @"&(cent|#162);", "\xa2", RegexOptions.IgnoreCase);

Htmlstring = Regex.Replace(Htmlstring, @"&(pound|#163);", "\xa3", RegexOptions.IgnoreCase);

Htmlstring = Regex.Replace(Htmlstring, @"&(copy|#169);", "\xa9", RegexOptions.IgnoreCase);



Htmlstring = Regex.Replace(Htmlstring, @"&#(\d );", "", RegexOptions.IgnoreCase);



Htmlstring.Replace("<", "");

Htmlstring.Replace(">", "");

Htmlstring.Replace("\r\n", "");

Htmlstring = HttpContext.Current.Server.HtmlEncode(Htmlstring).Trim();



return Htmlstring;

}

广告载入中

看看评论

快速回复

  • 支持UBB,HTML标签


  • 高级回复
  • 广告载入中
      
    操作选项: 加精 解精 奖惩 设专题 设公告 解公告 固顶 总固顶 解固顶 结帖 解结帖 锁帖 解锁 移帖 删帖   
    看看456-学习娱乐在线门户.致力为一切由互联网接入本站的朋友们,倾情打造一片学习娱乐新时空!
    Copyright ? 2007-2009 www.kankan456.com online services. All rights reserved. 浙ICP备07003587号
    欢迎您在看看发布各类原创作品和讨论话题,您的支持是“看看456”前进的基石