Hi,
I am using following code to Highlighting keywords in a text or resume.
My code:
// al is an Arraylist which have keywrods as .net, java, xml...
al = (ArrayList)Session["keyWords"];
for (int i = 0; i < al.Count; i++)
{
if (s.Contains(al[i].ToString().ToLower()) || s.Contains(al[i].ToString().ToUpper()) || s.Contains(al[i].ToString()))
{
//s = s.Replace(al[i].ToString(), "<b><font color='red'>" + al[i] + "</font></b>");
s = HighlightKeywords(s, al[i].ToString());
}
}
private static string HighlightKeywords(string text,string keywords)
{
// Swap out the ,<space> for pipes and add the braces
Regex r = new Regex(@", ?");
keywords = "(" + r.Replace(keywords, @"|") + ")";
// Get ready to replace the keywords
r = new Regex(keywords, RegexOptions.Singleline | RegexOptions.IgnoreCase);
// Do the replace
return r.Replace(text, new MatchEvaluator(MatchEval));
}
private static string MatchEval(Match match)
{
if (match.Groups[1].Success)
{
return "<b><font color='red'>" + match.ToString() + "</font></b>";
}
return ""; //no match
}
If i search .net,xml,java then it does not show java in JavaScript or Java.
please help me
Thanks in advance
Pankaj