using System.Text.RegularExpressions;

 /// <summary>

   /// 去除HTML标记

   /// </summary>

   /// <param name="DeleteHTML">包括HTML的源码 </param>

   /// <returns>已经去除Html标签后的文字</returns>

   public static string  DeleteHTML(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;

   }

.NET去掉HTML标记的更多相关文章

  1. C#去掉HTML标记

    该方法亲测可行,下面直接粘贴代码. public string RemoveHTMLTags(string htmlStream) { if (htmlStream == null) { throw ...

  2. 去掉HTML标记 .

    ///   <summary>     ///   去除HTML标记     ///   </summary>     ///   <param   name=" ...

  3. 使用C#将HTML文本转换为普通文本,去掉所有的Html标记(转)

    using System; using System.Collections.Generic; using System.Linq; using System.Text; //首先需要导入命名空间 u ...

  4. PHP压缩html网页代码原理(清除空格,换行符,制表符,注释标记)

    本博启用了一个叫wp super cache的页面压缩工具, 源代码没有去查看,不过原理很简单. 我们可以自己动手书写一个压缩脚本. 清除换行符,清除制表符,去掉注释标记 .它所起到的作用不可小视. ...

  5. 如何去掉HTML代码来获取纯文本?

    public string TextNoHTML(string Htmlstring) { //删除脚本 Htmlstring = Regex.Replace(Htmlstring, @"& ...

  6. 用VIM设置UTF-8编码的BOM标记

    1.去掉BOM标记: :set nobomb 2.加上BOM标记: :set bomb 3.查询当前UTF-8编码的文件是否有BOM标记: :set bomb? 4.更高级一点的: :%!xxd &q ...

  7. Aspose.Words简单生成word文档

    Aspose.Words简单生成word文档 Aspose.Words.Document doc = new Aspose.Words.Document(); Aspose.Words.Documen ...

  8. Git 分支管理和冲突解决

    Git 分支管理和冲突解决 创建分支 git branch 没有参数,显示本地版本库中所有的本地分支名称. 当前检出分支的前面会有星号. git branch newname 在当前检出分支上新建分支 ...

  9. C#夯实基础之接口(《CLR via C#》读书笔记)

    一. 接口的类型 接口是引用类型.因此从值类型赋值给接口是需要装箱的.如下所示: class Program { static void Main(string[] args) { ISay catS ...

随机推荐

  1. Android异步处理一:使用Thread+Handler实现非UI线程更新UI界面

    Android应用的开发过程中需要把繁重的任务(IO,网络连接等)放到其他线程中异步执行,达到不阻塞UI的效果. 下面将由浅入深介绍Android进行异步处理的实现方法和系统底层的实现原理. 本文介绍 ...

  2. iOS页面间传值的方式(NSUserDefault/Delegate/NSNotification/Block/单例)

    iOS页面间传值的方式(NSUserDefault/Delegate/NSNotification/Block/单例) 实现了以下iOS页面间传值:1.委托delegate方式:2.通知notific ...

  3. BS模式的模型结构详解

    编号:1004时间:2016年4月12日16:59:17功能:BS模式的模型结构详解 URL:http://blog.csdn.net/icerock2000/article/details/4000 ...

  4. Day04_JAVA语言基础第四天

    1.循环(掌握) 1.什么时候使用(理解) 如果我们发现有很多重复内容的时候就要使用循环 2.好处(理解) 让我们的代码看起来更精炼了 3.循环的组成(理解) 1 初始化条件:一般定义的是一个初始变量 ...

  5. OpenFlow Switch学习笔记(六)——Instructions和Actions

    本文主要重点讨论OpenFlow Switch规范的指令集,它们深刻影响着数据包在Switch中的处理行为,下面开始从以下几个部分谈起. 1.Instructions 每一个Flow Entry里都包 ...

  6. 【转】eclipse 安装插件

    eclipse安装插件或许没有什么多的可讲,但对于刚刚接触eclipse这款IDE的新手来说,可能还是会有点棘手! eclipse安装插件大致三种方法: 方法一:自身安装器 使用eclipse的Sof ...

  7. node模拟http服务器session机制-我们到底能走多远系列(36)

    我们到底能走多远系列(36) 扯淡: 年关将至,总是会在一些时间节点上才感觉时光飞逝,在平时浑浑噩噩的岁月里都浪费掉了太多的宝贵.请珍惜! 主题:      我们在编写http请求处理和响应的代码的时 ...

  8. hdu 2335 Containers

    水题,就不解释了,不过这个题有一点很好,就是枚举的时候,枚举宽,也就是列数,因为这样才能越来越接近正方形 #include<cstdio> #include<cstring> ...

  9. Debian中如何切换默认Python版本

    当你安装 Debian Linux 时,安装过程有可能同时为你提供多个可用的 Python 版本,因此系统中会存在多个 Python 的可执行二进制文件,你可以按照以下方法使用 ls 命令来查看你的系 ...

  10. ZOJ 1125 Floating Point Numbers

    原题链接 题目大意:给一个16位的数字,表示一个浮点数,按照规则转换成科学计数法表示. 解法:注释比较清楚了,注意浮点运算的四舍五入问题. 参考代码: #include<iostream> ...