views:

61

answers:

2

Can I get the string without the html tags which will be displayed on the webbrowser control ?

Like I have String str = "html hello html" then I want to find the string like hello.

How can I do that?

+2  A: 

You can use a regular expression to strip the html tags, like:

string html = "Your html string";
string x = Regex.Replace(html,@"<(.|\n)*?>", string.Empty);
thedugas
Here can I get the string excluding the html tags from the string in which html tags are there ?
Harikrishna
And Regex is what ?
Harikrishna
@thedugas Ok...It is the System.Text.RegularExpression.It works..Thanks...
Harikrishna
+2  A: 

Regular expressions aren't ideal for HTML. Regular expressions are for regular text, not HTML.

Use an HTML parser library such as the free, open source HTML Agility Pack. It comes bundled with an HTML-to-Text converter sample.

Judah Himango
@Judah - Thanks for posting that, looks sweet - can't wait to check it out.
thedugas
While true, in general, simply stripping tags ("things that begin with `<` and end with `>`") is quite suitable for a regex.
calmh
http://www.codinghorror.com/blog/2009/11/parsing-html-the-cthulhu-way.html
Judah Himango