• C# 清除文本中的HTML标签


    /// <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; 
            }
  • 相关阅读:
    小菜编程成长记(四 业务的封装)
    小菜学Flex2(二 currentState初步使用)
    小菜编程成长记(九 反射——程序员的快乐!)
    小菜编程成长记(一 面试受挫——代码无错就是好?)
    小菜编程成长记(六 关于Flex的争论)
    小菜编程成长记(三 复制VS复用)
    104种木马的清除方法
    细节决定成败打电话和发邮件的细节
    MS SQL Server查询优化方法
    美国西点军校最重要的行为准则:没有任何借口
  • 原文地址:https://www.cnblogs.com/a-mumu/p/5160393.html
Copyright © 2020-2023  润新知