方法一、完成查找關鍵字字體高亮顯示 string serkeys(string , string)#region 方法一、完成查找關鍵字字體高亮顯示 string serkeys(string , string)
/**//// <summary>
/// 完成查找關鍵字字體高亮顯示
/// </summary>
/// <param name="str">字符串</param>
/// <param name="sqlkey">字符串關鍵詞</param>
/// <returns>返回字符串</returns>
public static string serkeys(string str,string sqlkey)
...{
//sqlstr 待查找的關鍵字
//str 已經查找到帶有關鍵字的字符串
int len=sqlkey.Length;
int len1=str.Length;
string onesqlstr,rproname="";
rproname=str;
//去掉關鍵字頭和尾的空格,及將關鍵詞
sqlkey=sqlkey.Trim();
if (sqlkey.IndexOf(" ")>0)
...{
string [] kewArray=sqlkey.Split('' '');
rproname=str;
if (kewArray.Length>0)
...{
for(int i=0;i<=kewArray.Length-1;i++)
...{
onesqlstr =kewArray[i];
if(onesqlstr!="" && onesqlstr!=null)
...00000">{
if( str.IndexOf(onesqlstr)>=0)
&n rproname = rproname.Replace(onesqlstr,"<span style=''color:#ff0033''>"+onesqlstr+"</span>");
}
}
}
}
else
...{
onesqlstr=sqlkey;
if( str.IndexOf(onesqlstr)>=0)
rproname = rproname.Replace(onesqlstr,"<span style=''color:#ff0033''>"+onesqlstran>+"</span>");
}
return rproname;
}
#endregion
方法二、完成查找關鍵字字體高亮顯示,精確到每個字符#region 方法二、完成查找關鍵字字體高亮顯示,精確到每個字符
/**//// <summary>
/// 完成查找關鍵字字體高亮顯示,精確到每個字符
/// </summary>
/// <param name="str">字符串</param>
/// <param name="sqlkey">字符串關鍵詞</param>
/// <returns>返回字符串</returns>
public static string ;serkeys_char(string str,string sqlkey)
...{
//sqlstr 待查找的關鍵字
//str 已經查找到帶有關鍵字的字符串
int len=sqlkey.Length;
int len1=str.Length;
string onesqlstr,pproname,rproname="";
string [] memo= new string[len1];
for(int j=0;j<=len1-1;j++)
...{
onesqlstr=sqlkey;
pproname=str.Substring(j,1);
if (onesqlstr.ToLower().IndexOf(pproname.ToLower())>=0)
...{
[j]="<span style=''color:#ff0033''>"+pproname+"</span>";
}
else
...{
memo[j]=pproname;
}
}
for(int i=0;i<=memo.Length-1;i++)
...{
rproname+=memo[i];
}
="COLOR: #0000ff">return rproname;
}
#endregion