请教:如何给搜索关键字加颜色!! 本人正实现数据搜索功能,发现一难题: 如何在搜索到的内容中给搜索关键字加颜色。不胜感激!! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 写一函数,如下 public static string GetColorString(string old,string key) { char[] sp={' ','|','\'',';',':','-','(',')'}; string[] arrkey=key.Split(sp); foreach(string temp in arrkey) { if(temp!="") { Match m=Regex.Match(old,temp,RegexOptions.IgnoreCase); if(m.Success) { string str_m=m.Value; old=old.Replace(str_m,"<span class=a>"+str_m+"</span>"); } } } return old; }参数old位要显示的字符,key位搜索的字符 class=a 就可以设置颜色,直接用color=red也可以 see:http://search.csdn.net/Expert/topic/2112/2112690.xml?temp=.3626215 在输出的时候直接把关键字替换一下就OK呀string result;……result=result.Replace(keyword,"<font color='red'>"+keyword+"</font>"); sql 问题 外链js调用页面后台程序 正则表达式 关于页面传值的问题? 在线等...请各位朋友看下? 怎样让调整页面宽度 高分求救,安装好.net后不能用.............. 请问代码错在哪里了??关于上传 在使用DataGrid里的TextBox时,如何才能做到,不是每个column都出现TextBox,就是说我想限定哪些可以编辑。多谢 为什么换条语句就运行不了了?请大家帮忙! 请问高手,ASP.NET什么好书,本人想在这方面发展!! DataView.RowFilter属性的一个问题? 高求请教一个动态加载UserControl的视图状态问题!!
public static string GetColorString(string old,string key)
{
char[] sp={' ','|','\'',';',':','-','(',')'};
string[] arrkey=key.Split(sp);
foreach(string temp in arrkey)
{
if(temp!="")
{
Match m=Regex.Match(old,temp,RegexOptions.IgnoreCase);
if(m.Success)
{
string str_m=m.Value;
old=old.Replace(str_m,"<span class=a>"+str_m+"</span>");
}
} }
return old; }
参数old位要显示的字符,key位搜索的字符
string result;
……
result=result.Replace(keyword,"<font color='red'>"+keyword+"</font>");