How to remove all HTML Tags from specified string.

Here is a interesting piece of code to remove all tags.
Specially Html tags are remove and remains plain text.

//A pattern to find the HTML Tags
const string HTML_TAGS = "<.*?>";
public static string RemoveHTML(string inputstr)
return Regex.Replace(inputstr, HTML_TAGS, string.Empty);

Now implement this RemoveHTML function in Button Click

//In Button's Click
label1.Text = RemoveHTML("THIS IS TITLETHIS IS BODY");
label1.Text = RemoveHTML(textBox1.Text);

Try out with some examples.


No responses found. Be the first to comment...

  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name: