views:

93

answers:

2

Basically what I want to do is, in C#, to take a string variable with some HTML and another with a search string in it and send them both to a method that returns whether or not it found anything and if so it returns a string variable that has the HTML with the search string highlighted in it. Are there any good libraries out there that have this sort of functionality? I'm not looking for alot of bells and whistles, just basically what I described above.

Thanks,

Jeff

A: 

why would something like this not work for you?

public static string HighLightMAtchingText(string html, string text)
        {
            html.Replace(html, String.Format("<span class=\"highlight\">{0}</span>", text));
            return html;
        }

it returns all instances of the text with html to High light the passed in text

if you wanted to do more use Regex.Replace() and add some regular expressions to better qualify your replace.

Bob The Janitor
That's a good answer Bob. My only thing is, you should return a the given HTML string in a <span>{0}</span> block, not a <style> block; as those are only used to define CSS; not assign a class to a given HTML block.
Frank Rosario
mistype, fixed now
Bob The Janitor
+1  A: 

Html Agility Pack for manipulating html tag soup like it's structured xml.

blue_fenix