zoukankan      html  css  js  c++  java
  • 删除HTML代码

    /// <summary>
            /// 删除HTML代码
            /// </summary>
            /// <param name="o">Html代码</param>
            /// <returns></returns>
            public static string ClearHTML(object o)
            {
                string Htmlstring = o.ToString();
                //删除脚本  
                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.Replace("<", "");
                Htmlstring.Replace(">", "");
                Htmlstring.Replace("\r\n", "");
                //Htmlstring = HttpContext.Current.Server.HtmlDecode(Htmlstring).Trim();
                return Htmlstring.Trim();
            }
  • 相关阅读:
    实现vue项目改造服务端渲染
    vue项目seo问题简单解决,并生成sitemap
    vue element-table滚动条样式修改
    vue全局注册事件
    获取浏览器数据
    vscode配置,vue开发环境
    在项目中使用facebook聊天插件
    linux配置nuxt项目
    Vue中实现div编辑效果,及contenteditable设置为plaintext-only与true的区别
    js中判断对象是否存在
  • 原文地址:https://www.cnblogs.com/xsmhero/p/1772661.html
Copyright © 2011-2022 走看看