/// <summary> 

        /// 清除文本中Html的标签 
        /// </summary> 
        /// <param name="Content"></param> 
        /// <returns></returns> 
        public static string ClearHtml(string Content) 
        
            Content = Zxj_ReplaceHtml("&#[^>]*;""", Content); 
            Content = Zxj_ReplaceHtml("</?marquee[^>]*>""", Content); 
            Content = Zxj_ReplaceHtml("</?object[^>]*>""", Content); 
            Content = Zxj_ReplaceHtml("</?param[^>]*>""", Content); 
            Content = Zxj_ReplaceHtml("</?embed[^>]*>""", Content); 
            Content = Zxj_ReplaceHtml("</?table[^>]*>""", Content); 
            Content = Zxj_ReplaceHtml(" """, Content); 
            Content = Zxj_ReplaceHtml("</?tr[^>]*>""", Content); 
            Content = Zxj_ReplaceHtml("</?th[^>]*>""", Content); 
            Content = Zxj_ReplaceHtml("</?p[^>]*>""", Content); 
            Content = Zxj_ReplaceHtml("</?a[^>]*>""", Content); 
            Content = Zxj_ReplaceHtml("</?img[^>]*>""", Content); 
            Content = Zxj_ReplaceHtml("</?tbody[^>]*>""", Content); 
            Content = Zxj_ReplaceHtml("</?li[^>]*>""", Content); 
            Content = Zxj_ReplaceHtml("</?span[^>]*>""", Content); 
            Content = Zxj_ReplaceHtml("</?div[^>]*>""", Content); 
            Content = Zxj_ReplaceHtml("</?th[^>]*>""", Content); 
            Content = Zxj_ReplaceHtml("</?td[^>]*>""", Content); 
            Content = Zxj_ReplaceHtml("</?script[^>]*>""", Content); 
            Content = Zxj_ReplaceHtml("(javascript|jscript|vbscript|vbs):""", Content); 
            Content = Zxj_ReplaceHtml("on(mouse|exit|error|click|key)""", Content); 
            Content = Zxj_ReplaceHtml("<\\?xml[^>]*>""", Content); 
            Content = Zxj_ReplaceHtml("<\\/?[a-z]+:[^>]*>""", Content); 
            Content = Zxj_ReplaceHtml("</?font[^>]*>""", Content); 
            Content = Zxj_ReplaceHtml("</?b[^>]*>""", Content); 
            Content = Zxj_ReplaceHtml("</?u[^>]*>""", Content); 
            Content = Zxj_ReplaceHtml("</?i[^>]*>""", Content); 
            Content = Zxj_ReplaceHtml("</?strong[^>]*>""", Content); 
            Content = Zxj_ReplaceHtml("</?strong[^>]*>""", Content); 
   
            Content = Zxj_ReplaceHtml(" """, Content); 
            Regex r = new Regex(@"\s+"); 
            Content = r.Replace(Content, ""); 
   
            Content.Trim(); 
            string clearHtml = Content; 
            return clearHtml; 
        
   
        /// <summary> 
        /// 清除文本中的Html标签 
        /// </summary> 
        /// <param name="patrn">要替换的标签正则表达式</param> 
        /// <param name="strRep">替换为的内容</param> 
        /// <param name="content">要替换的内容</param> 
        /// <returns></returns> 
        private static string Zxj_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; 
        }

C# 清除文本中的HTML标签的更多相关文章

  1. 清除文本中Html的标签

    /// <summary> /// 清除文本中Html的标签 /// </summary> /// <param name="Content"> ...

  2. js 清除文本中的html标签

    text.replace(/<[^>]+>/g,"");

  3. 去除富文本中的html标签及vue、react、微信小程序中的过滤器

    在获取富文本后,又只要显示部分内容,需要去除富文本标签,然后再截取其中一部分内容:然后就是过滤器,在微信小程序中使用还是挺多次的,在vue及react中也遇到过 1.富文本去除html标签 去除htm ...

  4. python去除文本中的HTML标签

    def SplitHtmlTag(file): with open(file,"r") as f,open("result.txt","w+" ...

  5. Android检测富文本中的<img标签并实现点击效果

    本文旨在:通过点击一张图片Toast输出位置与url链接. 闲话少说,实现原理大概是酱紫的::通过正则表达式检测富文本内的图片集合并获取url,在src=“xxx” 后面添加 onclick方法,至于 ...

  6. 清除大文本中的html标签

    public String clearHtmlText(String inputString) { if (StringUtils.isBlank(inputString)) { return &qu ...

  7. 过滤掉文本中的javascript标签代码

    2014年1月21日 11:51:19 php代码: $content = preg_replace('#<\s*[script].*>#', '', $a);//有些攻击可以在scrip ...

  8. HTML中的图片标签的用法!

    在HTML中<img>这个标签是定义文本中的图片标签,它的作用就比如说可以提供图片的名字.提供图片的尺寸大小和提供图片的一些图片属性,比如Alt这个属性,可以给图片一个名称来告诉朋友们.这 ...

  9. 如何使用JS脚本从HTML中分离图片标签与文本,替换文本中指定的内容并加粗(原创)

    var html='ddfsdfsdfdsd dfsdfsdffds<img _src="http://localhost:8490/60E86EA7-FE7B-44BF-8270-4 ...

随机推荐

  1. nginx如何写日志

    写日志函数为ngx_log_error_core,位于src/core/ngx_log.c:89行核心代码如下:while (log) { if (log->log_level < lev ...

  2. TCP连接问题之CLOSE_WAIT和TIME_WAIT过多

    参考博文 https://dengqsintyt.iteye.com/blog/2086485 Timeout waiting for connection异常排查:https://blog.csdn ...

  3. hystrix(4) properties配置

    这一节我们来讲hystrix的properties配置体系,properties配置也是各个功能模块的基础功能.hystrix将配置分成三个部分: 1.HystrixCommandProperties ...

  4. 3.Kafka集群配置

  5. Ubuntu16.04 Nvidia显卡驱动简明安装指南

    简单得整理了一下Ubuntu16.04 Nvidia显卡驱动的安装步骤: 查看当前系统显卡参数: sudo lspci | grep -i nvidia 删除之前的驱动: sudo apt-get - ...

  6. 关于struts1与struts2

    1.Action方面 Action是整个Struts框架的核心内容,Struts1.x与Struts2的Action模型很大的区别.Struts2是一个 pull-MVC架构 ,从开发者角度看,就是说 ...

  7. ViewBinding的简单使用

    Android自家的,又可以省去findviewbyid(),而且Butterknife上大神都已经推荐使用的,还有什么理由不去改写呢 build.gradle 开启viewBinding功能 and ...

  8. (转载)CPU基础知识

    本文转载自网络. 如有侵权,请联系处理!   简介 中央处理器(CPU,Central Processing Unit)是一块超大规模的集成电路,是一台计算机的运算核心(Core)和控制核心( Con ...

  9. Python练习题 005:三个数字由大到小排序输出

    [Python练习题 005]输入三个整数x,y,z,请把这三个数由小到大输出. ----------------------------------------------------------- ...

  10. Book of Shaders 00 - 使用 VS Code 编写 GLSL

    0x00 写在前面 最近在学习由 Patricio 编写的 The Book of Shaders,这是一本关于 Fragment Shaders(片段着色器)的入门指南.为了在一个相对熟悉的平台运行 ...