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

Hi,

I am using following code to Highlighting keywords in a text or resume.

My code:

string keywords = ".net";
        string text = "These are technologies: .net, intranet, NET, net,ASP.net.";

        Response.Write(HighlightKeywords(keywords, text));



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
    }

The output should be shown as

These are technologies: .net, intranet, NET, net,ASP.net.

but it showing as:

These are technologies: .net, intranet, NET, net,ASP.net.

please help me

Thanks in advance

Pankaj

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.