首页 > 其他 > 详细

新闻内容显示样式去除

时间:2014-02-09 15:22:42      阅读:337      评论:0      收藏:0      [点我收藏+]

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

 

用方法去除样式

 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("\r\n", "");
        htmlstring.Replace("\t", "");
        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())%> 

新闻内容显示样式去除

原文:http://www.cnblogs.com/licuihua/p/3540452.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!