阅读教程

C#过滤HTML代码教程源码

[日期:2008-06-30] 来源:CSDN  作者:志伟
C#过滤HTML代码教程源码

public string NoHTML(string Htmlstring) //去除HTML标记

  {     

//删除脚本   

 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;  

 }

 

(责任编辑:志伟

  转载本站点内容时请注明来自 志伟教程资料网。如不注明, 志伟将根据《互联网著作权行政保护办法》追究其相应法律责任。



      
      使用百度搜索:C#过滤HTML代码教程源码百度中搜索:C#过滤HTML代码教程源码
阅读:
录入:志伟

评论 】 【 推荐 】 【 打印
上一篇:C#获取MAC地址源码
下一篇:c# ajax教程源码下载之Ajax用户注册检测是否存在
本文评论       全部评论
发表评论


点评: 字数
姓名:

 
搜一下


 
本周热门教程
 

关于我们 | 广告合作 | 法律声明 | 联系站长 | 网站地图 | 网站搜索 | | Top ↑
Copyright © 志伟教程资料网 Powered by zhiweinet 1.0
 本栏目提供:C#过滤HTML代码教程源码