我做了一个博客 日志列表里显示的日志的标题和日志内容的前50个字符
开始测试都没问题 可是有一个日志我把图片放前面了 也就是说一开始是图片
然后才是字符
结果日志列表里就只有一个标题 日志内容的前50个字符读不出来了怎么才能解决这个问题
谢谢

解决方案 »

  1.   

    我写了一个可是不管用我是用FCKeditor1.Value 直接存进数据库的
    我去看了一下数据库里面没有 img这种东西 怎么办呀content.Replace("<img[^>]*>","");
      

  2.   

    在显示50个数之前调用这个函数
     public static string wipescript(string html)
         {
             System.Text.RegularExpressions.Regex regex0 = new System.Text.RegularExpressions.Regex(@"<(.[^>]*)>", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
             System.Text.RegularExpressions.Regex regex1 = new System.Text.RegularExpressions.Regex(@"(\<.[^\<]*\>)", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
             System.Text.RegularExpressions.Regex regex2 = new System.Text.RegularExpressions.Regex(@"(\<\/[^\<]*\>)", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
             System.Text.RegularExpressions.Regex regex3 = new System.Text.RegularExpressions.Regex(@"<(.[^>]*)>", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
             System.Text.RegularExpressions.Regex regex4 = new System.Text.RegularExpressions.Regex(@"<iframe[\s\s]+</iframe *>", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
             System.Text.RegularExpressions.Regex regex5 = new System.Text.RegularExpressions.Regex(@"<frameset[\s\s]+</frameset *>", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
             System.Text.RegularExpressions.Regex regex6 = new System.Text.RegularExpressions.Regex(@"<(\S*?)[^>]*>.*? </\1> | <.*?/>", System.Text.RegularExpressions.RegexOptions.IgnoreCase);        html = regex0.Replace(html, "");
            html = regex1.Replace(html, "");
            html = regex2.Replace(html, "");
            html = regex3.Replace(html, "");
            html = regex4.Replace(html, "");
            html = regex5.Replace(html, "");
            html = regex6.Replace(html, "");
            return  html;
         }
      

  3.   

      //清除html标记并截取前50个字符
      protected string FormatStr(string str)
        {
            str = System.Text.RegularExpressions.Regex.Replace(str, "<[^>]+>", "");
            str = str.Length > 50 ? str.Substring(0, 50) + "..." : str;
            return str;
        }