Пример #1
0
        //中心动态,搜的都是要有图片的新闻
        public string LoadToutiaoNews()
        {
            List <T_Article> list = bll.GetListByContent(5, 2);
            StringBuilder    sb   = new StringBuilder();
            int i = 0;

            foreach (var model in list)
            {
                //获得文章内容的简介
                T_Article first = new T_Article();
                first = bll.GetArticleById(model.ArticleId);

                string ab = Regex.Replace(first.ArticleContent, @"<.*?>", "");
                //如果文字没有超过100个字
                if (ab.Length > 70)
                {
                    ab = ab.Substring(0, 70);
                }
                ab = ab + "...";


                if (i == 0)
                {
                    //第一张提取图片
                    //精简文章主题内容
                    string imgurl = ImgHelper.getImgUrl(first.ArticleContent, @"<img[^>]+src=\s*(?:'(?<src>[^']+)'|""(?<src>[^""]+)""|(?<src>[^>\s]+))\s*[^>]*>", "src")[0].ToString();
                    sb.AppendFormat("<a href='articleDetail.aspx?articleId={0}'><img src='{1}'/></a><h3>{2}</h3><p>{3}</p>", model.ArticleId, imgurl, model.ArticleTitle, ab);
                    sb.AppendFormat("</div><div class='newsright'>");
                }
                else
                {
                    sb.AppendFormat("<a href='articleDetail.aspx?articleId={0}'> <p class='nrtitle'>{1}</p></a><p class='nrtxt' style='font-size:0.84vw;'>{2}</p>", model.ArticleId, model.ArticleTitle, ab);
                }
                i++;
            }
            return(sb.ToString());
        }