zoukankan      html  css  js  c++  java
  • 新闻内容显示样式去除

    在显示新闻内容的时候会出现显示内容出错存在兼容问题

    用方法去除样式

     public static string RemoveHtml(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, @"(^\s*)|(\s*$)", "", RegexOptions.IgnoreCase);
            htmlstring = Regex.Replace(htmlstring, @"^( )+|^[\s ]+|( )+$|[\s ]+$", "", RegexOptions.IgnoreCase);
            htmlstring.Replace("<", "");
            htmlstring.Replace(">", "");
            htmlstring.Replace(" ", "");
            htmlstring.Replace(" ", "");
            htmlstring = HttpContext.Current.Server.HtmlEncode(htmlstring).Trim();
            return htmlstring;

        } 

    加上去之后进行应用页面的使用

    <%#RemoveHtml(Eval("details").ToString()).Length > 55 ? RemoveHtml(Eval("details").ToString()).Substring(0, 55) : RemoveHtml(Eval("details").ToString())%> 

  • 相关阅读:
    《棉花帝国:一部资本主义全球史》笔记
    关于”空杯之心“的重新思考
    《光荣与梦想:19321972年美国叙事史》笔记
    《哥伦布大交换:1492年以后的生物影响和文化冲击》笔记
    《增长、短缺与效率》笔记
    《逃不开的经济周期:历史、理论与投资现实》笔记
    《经济学》笔记
    《就业、利息和货币通论》笔记
    PostgreSQL与MySQL比较
    让svn自动更新代码注释中的版本号
  • 原文地址:https://www.cnblogs.com/licuihua/p/3540452.html
Copyright © 2011-2022 走看看