Remove Html Tags from A String

In the web application development we often need to strip HTML tags from the string that comes from input boxes.

This code snippet will strip a string of all Html tags and replace a tag with a blank space (You can alternatively replace it with String.Empty but this often leads to words being joined).

   1:  using System.Text.RegularExpressions; 
   2:   
   3:  const string HTML_TAGS = "<.*?>"; 
   4:   
   5:  static string StripHTML (string inputString)
   6:  {   
   7:        return Regex.Replace(inputString, HTML_TAGS , " ");
   8:  }
Enjoy Programming …
Posted by: Manish

Categories: C#, ASP.NET

Tags:

Add comment

  Select your country

biuquote
  • Comment
  • Preview
Loading