如何将新闻正文中的“微软”加上链接?而数据库里并没此链接。。像新浪新闻那样,关键词自动加上链接。我用Regex类中的Replace试了一下,全所有正文中的“微软”都替换了,有什么方法只替换第一个?应该如何实现?
解决方案 »
- 求助asp CheckBox 传值问题
- 求一个超简单的ASP.NET做的论坛源码
- 百分求:关于WebBrowser,web与winform交互
- 问一个AJAX问题
- 从SQL2005的数据库里导出数据到Excel(很头疼的)
- fckeditor中加导入WORD文档插件功能,但在有的浏览器中确定按钮无效,WORD文档内容无法到fckeditor编辑器内容框中
- DataGrid+DropDownList绑定已没问题,如何实现在编辑这一行时,DropDownList可以停在数据库里数据所处的位置?
- 急!急!急!关于.net版本问题?
- asp.net能做出语音聊天室吗
- 怎样让事件触发后弹出一个没有“前进””后退“之类的页面,类似于网站的广告样子
- 我在本机测试可以,但传到服务器上就这样了,大家帮看看是怎么回事儿???
- 一个小小小问题!!
int startIndex = content.IndexOf("微软") + 2 ;string Result = content.SubString( 0 ,startIndex ).Replace( "微软" ,"<a href='Microsoft.com'>" ) + content.SubString( startIndex ) ;
string GsKeywords(string content){
string strC=content;
Hashtable ht = new Hashtable();
ht.Add("微软","http://www.microsoft.com");
ht.Add("大河报","http://www.dahedaily.com");
ht.Add("奥迪","http://www.audi.com.cn");
ht.Add("大众汽车","http://www.vw.com.cn");
ht.Add("上海大众","http://www.csvw.com");
ht.Add("郑州世纪鸿图丰田","http://auto.i-style.cn/sjft");
ht.Add("河南弘通","http://www.hn-auto.com/htm6/index.php");
ht.Add("上汽通用五菱","http://www.sgmw.com.cn");
ht.Add("福特公司","http://www.ford.com.cn");
ht.Add("奇瑞汽车","http://www.chery.cn");
ht.Add("北京现代","http://www.beijing-hyundai.com.cn");
IDictionaryEnumerator ie = ht.GetEnumerator();
int i=0;
while(ie.MoveNext()){
i=strC.IndexOf(ie.Key.ToString());
if(i!=-1){
strC = strC.Substring(0,i) + "<a class=\"keyword NrTxt\" href=\""+ie.Value+"\" Target=\"_blank\">" + ie.Key+ "</a>" + strC.Substring(i+ie.Key.ToString().Length);
}
}
//strC = Regex.Replace (strC,ie.Key.ToString(),"<a class=\"keyword NrTxt\" href=\""+ie.Value+"\" Target=\"_blank\">" + ie.Key + "</a>",RegexOptions.None);
return strC;
}
不过用Replace(content,"微软","<a herf=http://www.microsoft.com>微软</a>")的方法比较简单易懂。
CSDN小助手是一款脱离浏览器也可以访问Csdn论坛的软件
界面:http://blog.csdn.net/Qqwwee_Com/archive/2005/11/05/523395.aspx
下载:http://szlawbook.com/csdnv2
有没有 用 JavaScript 在客户端加链接标记的方法?