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里面
截取关键字高亮作为搜索结果
最新推荐文章于 2024-08-16 13:30:00 发布