• 去除文字里的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标签缺省或配合混乱。

  • 相关阅读:
    sqlserver计算时间差DATEDIFF 函数
    C# join 子句(C# 参考)
    C# join 子句(C# 参考)
    MongoDB 监控备份工具MMS
    MongoDB 监控备份工具MMS
    mongodb$slice (aggregation)
    mongodb$slice (aggregation)
    1004:字符三角形
    1004:字符三角形
    1003:对齐输出
  • 原文地址:https://www.cnblogs.com/hougelou/p/2854504.html
Copyright © 2020-2023  润新知