/// <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. [LeetCode]15. 三数之和(数组)(双指针)

    题目 给定一个包含 n 个整数的数组 nums,判断 nums 中是否存在三个元素 a,b,c ,使得 a + b + c = 0 ?找出所有满足条件且不重复的三元组. 注意:答案中不可以包含重复的三 ...

  2. 不定方程(Exgcd)

    #include<cstdio> using namespace std; int x,y; inline int abs(int a){return a>?a:-a;} int e ...

  3. firewalld 防火墙

    firewalld防火墙   firewalld简述 firewalld:防火墙,其实就是一个隔离工具:工作于主机或者网络的边缘对于进出本主机或者网络的报文根据事先定义好的网络规则做匹配检测,对于能够 ...

  4. spring mvc(1) 为什么要使用mvc

    在使用spring mvc之前,我们首先要理解我们为什么要使用spring mvc.关于这个问题我们可以看一下java web的简单发展过程. 1. servlet 开发阶段 上世纪90年代,随着In ...

  5. 新手接触springboot

    新手使用springboot或者说,刚接触java行业,有些不明白的就是项目的架构是怎么样的,我今天在这儿稍微整理了一下 有些新手可能在想,springboot是怎么解决最原始的增-删-改-查, 快速 ...

  6. Java中的常见锁(公平和非公平锁、可重入锁和不可重入锁、自旋锁、独占锁和共享锁)

    公平和非公平锁 公平锁:是指多个线程按照申请的顺序来获取值.在并发环境中,每一个线程在获取锁时会先查看此锁维护的等待队列,如果为空,或者当前线程是等待队列的第一个就占有锁,否者就会加入到等待队列中,以 ...

  7. 轻轻松松学CSS:overflow

    一.overflow的定义 overflow,音[əʊvəˈfləʊ],义[溢出],就像2.2米的人躺在1.8米的床上,腿得耷拉到床外一样.overflow 属性用于控制内容溢出容器时显示的方式 二. ...

  8. Python-求序列长度和序列长度协议-len() __len__

    len() 求序列的长度 print(len("beimenchuixue")) print(len([1, 2, 3])) __len__ 对象中实现这个方法,则 len() 方 ...

  9. 放弃"指针常量"这种不严谨的中文描述!深度理解数组名、指针常量

    ques1: 数组名完全等价于指针常量吗? int array[10] = { 10,11,12,13,14,15 }; printf("sizeof(array)= %d \n" ...

  10. C++ 构造函数 隐式转换 深度探索,由‘类对象的赋值操作是否有可能调用到构造函数’该实验现象引发

    Test1 /** Ques: 类对象的赋值操作是否有可能调用到构造函数 ? **/ class mystring { char str[100]; public: mystring() //myst ...