zoukankan      html  css  js  c++  java
  • 去除文字里的html标签的C#方法

    /// <summary>
            /// 清除文本中Html的标签
            /// </summary>
            /// <param name="Content"></param>
            /// <returns></returns>
            protected 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);
                string clearHtml = Content;
                return clearHtml;
            }

    为何要把文字内的html标签去掉呢,是因为在绑定的时候,浏览器会把标签的释义,释义之后会有可能将我们原有的布局打乱。所以,当只展示文字的时候,我们就要这样去做了。遇到这个问题是,在我绑定产品详情的时候遇到的,超过一定字数就截取字符,可以这样又会造成html标签缺省或配合混乱。

  • 相关阅读:
    在HQL里使用set方式设置的变量
    Nuxt.js 使用vue-social-share.js 插件 分享功能实践
    渗透测试被动信息搜集工具v0.1
    burp工具tips集合
    Go语言之数据类型(二)
    Go语言之数据类型(一)
    Go语言之变量
    Go语言快速入门
    Go语言环境搭建
    [SSH]基础知识——SSH、对称加密、非对称加密、公钥、私钥、中间人攻击
  • 原文地址:https://www.cnblogs.com/hougelou/p/2854504.html
Copyright © 2011-2022 走看看