截取关键字高亮作为搜索结果
2015-09-25 11:29
489 查看
if (dtt.Rows.Count > 0) { int count = 0; foreach (DataRow dr in dtt.Rows) { count++; int tid = Convert.ToInt32(dr["TId"].ToString()); string title; string content; title = dr["PTitle"].ToString(); content=dr["Content"].ToString(); int startIndex = content.IndexOf(key); if (content.Length > 22) { string contentBefore = dr["Content"].ToString().Substring(startIndex - 22>0?startIndex - 22:0, 22); string contentAfter = dr["Content"].ToString().Substring(startIndex + key.Length,22); content = "..." + contentBefore + key + contentAfter + "..."; } sb.Append("<li class=\"text-overflow\"><dl><dt><a href=\"" + HttpContext.Current.Request.Url.AbsolutePath + "q_" + tid + ".html\">" + title + "</a></dt><dd>" + content + "</dd></dl></li>"); }这边截取的是关键字左边22和右边22的内容放在Ul和li嵌套的Dl,dt里面
相关文章推荐
- Leetcode NO.279 Perfect Squares
- linux 驱动之led子系统(一)
- QT中setfilter()函数
- 算法为王:且看Mac Mini如何超越1636节点的Hadoop
- Js apply()使用详解
- Ajax学习笔记2之使用Ajax和XML
- 搜狐2016笔试1 扎金花
- 使用VC++使用开发Web服务(ISAPI extension - mod_gsoap.dll)1
- 分布式中使用 Redis 实现 Session 共享(中)
- Android中ClearEditText实现点击EditText输入框右边清除图标来清除输入内容的两种方式
- navigationController在pop时,指定pop到某个页面
- CADisplayLink 和 NSTimer
- poj 1163 The Triangle 动态规划
- DataTable.select如何选择后放在指定DataTable
- 欢迎使用CSDN-markdown编辑器
- 机器学习经典论文/survey合集 - 算法组
- Android异步下载网络图片
- poj 1163 The Triangle 动态规划
- 表情软键盘
- Spring3中用注解直接注入properties中的值