zoukankan      html  css  js  c++  java
  • 过滤html标签

            /// <summary>
            /// 过滤html标签
             /// </summary>
            /// <param name="Htmlstring"></param>
            /// <returns></returns>
            public static string NoHTML(string Htmlstring)
            {
                //删除脚本 
                  Htmlstring = Regex.Replace(Htmlstring, @"<script[^>]*?>.*?</script>", "", RegexOptions.IgnoreCase);
                //删除HTML  
                Htmlstring = Regex.Replace(Htmlstring, @"<(.[^>]*)>", "", RegexOptions.IgnoreCase);
                Htmlstring = Regex.Replace(Htmlstring, @"([\r\n])[\s]+", "", RegexOptions.IgnoreCase);
                Htmlstring = Regex.Replace(Htmlstring, @"-->", "", RegexOptions.IgnoreCase);
                Htmlstring = Regex.Replace(Htmlstring, @"<!--.*", "", RegexOptions.IgnoreCase);
                Htmlstring = Regex.Replace(Htmlstring, @"&(quot|#34);", "\"", RegexOptions.IgnoreCase);
                Htmlstring = Regex.Replace(Htmlstring, @"&(amp|#38);", "&", RegexOptions.IgnoreCase);
                Htmlstring = Regex.Replace(Htmlstring, @"&(lt|#60);", "<", RegexOptions.IgnoreCase);
                Htmlstring = Regex.Replace(Htmlstring, @"&(gt|#62);", ">", RegexOptions.IgnoreCase);
                Htmlstring = Regex.Replace(Htmlstring, @"&(nbsp|#160);", "   ", RegexOptions.IgnoreCase);
                Htmlstring = Regex.Replace(Htmlstring, @"&(iexcl|#161);", "\xa1", RegexOptions.IgnoreCase);
                Htmlstring = Regex.Replace(Htmlstring, @"&(cent|#162);", "\xa2", RegexOptions.IgnoreCase);
                Htmlstring = Regex.Replace(Htmlstring, @"&(pound|#163);", "\xa3", RegexOptions.IgnoreCase);
                Htmlstring = Regex.Replace(Htmlstring, @"&(copy|#169);", "\xa9", RegexOptions.IgnoreCase);
                Htmlstring = Regex.Replace(Htmlstring, @"&#(\d+);", "", RegexOptions.IgnoreCase);
                Htmlstring = Regex.Replace(Htmlstring, @"&#(\d+);", "", RegexOptions.IgnoreCase);
                Htmlstring = Regex.Replace(Htmlstring, @"&(ldquo);", "“°", RegexOptions.IgnoreCase);
                Htmlstring = Regex.Replace(Htmlstring, @"&(rdquo);", "”±", RegexOptions.IgnoreCase);
                Htmlstring = Regex.Replace(Htmlstring, @"&(mdash);", "—a", RegexOptions.IgnoreCase);
                Htmlstring.Replace("<", "");
                Htmlstring.Replace(">", "");
                Htmlstring.Replace("\r\n", "");
                Htmlstring = HttpContext.Current.Server.HtmlEncode(Htmlstring).Trim();
                return Htmlstring;
            }
    
  • 相关阅读:
    PTA(Basic Level)1048.数字加密
    PTA(Basic Level)1037.在霍格沃茨找零钱
    PTA(Basic Level)1030.完美数列
    PTA(Basic Level)1047.编程团体赛
    PTA(Basic Level)1087.有多少不同的值
    PTA(Basic Level)1077.互评成绩计算
    PTA(Basic Level)1027.打印沙漏
    PTA(Basic Level)1029.旧键盘
    记录一次排查挖矿:快速跟踪一个进程
    JVM性能、多线程排查常用命令
  • 原文地址:https://www.cnblogs.com/Setme/p/2537136.html
Copyright © 2011-2022 走看看