设为首页 加入收藏

TOP

获取一段HTML文本中的第一张图片与截取内容摘要(二)
2019-09-03 01:57:27 】 浏览:35
Tags:获取 HTML 文本 第一 图片 截取 内容 摘要
s) + 1; if (size < length) { sb.Append(content.Substring(pos, npos - pos)); } else { if (!notr && next.IndexOf("/tr") == 0) { sb.Append(content.Substring(pos, npos - pos)); notr = true; } } } else if (next.IndexOf("td") == 0 || next.IndexOf("/td") == 0) { npos = content.IndexOf(">", pos) + 1; if (size < length) { sb.Append(content.Substring(pos, npos - pos)); } else { if (!notr) { sb.Append(content.Substring(pos, npos - pos)); } } } else { npos = content.IndexOf(">", pos) + 1; sb.Append(content.Substring(pos, npos - pos)); } if (npos <= pos) npos = pos + 1; pos = npos; } else { if (size < length) { sb.Append(cur); size++; } else { if (!firststop) { sb.Append("……"); firststop = true; } } pos++; } } return sb.ToString(); } } #endregion View Code

注意:方法中的bool StripHTML参数表示是否以HTMl文本方式输出,如果为True的话表示去除HTML标签与样式,截取到的是纯文本,反之就是以HTMl文本输出。

这样我们就可以根据自己喜欢的方式来输出文本。

 

首页 上一页 1 2 下一页 尾页 2/2/2
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇Split方法,拆分字符串后,去除返.. 下一篇在线课程笔记—.NET基础

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目