What is the best way to search for HTML in a C # line for specific text and tagging text?

What would be the best way to search HTML inside a C # string variable to find a specific word / phrase and mark (or wrap) that word / phrase with highlighted color?

Thanks,

Jeff

+5
source share
6 answers

I like to use the Html Agility Pack is very easy to use, although recently there are not many updates in it, it can still be used. For example, capturing all links

HtmlWeb client = new HtmlWeb();
HtmlDocument doc = client.Load("http://yoururl.com");            
HtmlNodeCollection Nodes = doc.DocumentNode.SelectNodes("//a[@href]");         

foreach (var link in Nodes)
{                
    Console.WriteLine(link.Attributes["href"].Value);
}
+7
source

Regular expression will be my way .;)

+1
source

HTML, XHTML-, XML-, XPath/XSL - , ?

, , HTMLTidy HTML XHTML, XSL/XPath , .

, , , .., .

+1

.

string input = "ttttttgottttttt";
string output = Regex.Replace(, "go", "<strong> $0 </strong> " );

: "tttttt <strong> go </strong> ttttttt"

HTML, , . , HTML:

< span class= "firstLetter" > B </span> ook

"", HTML. , , , .

+1

Html DOM - SourceForge.net. , .

+1

Search strings, you need to search for regular expressions. As for labeling, after you have a substring position, it should be simple enough to use this to add something to wrap a phrase.

0
source

All Articles