Support | Contact Us
Search:

Strip HTML Tags In C#

Share: More

While working on our content manager, I've found that at times I want to remove HTML that a user may have entered into a field where HTML is not allowed. This is pretty easy to do using regular expressions. Here's how I implemented HTML tag removal in C#:
using System.Text.RegularExpressions;

public string Strip(string text)
{
    return Regex.Replace(text, @"<(.|\n)*?>", string.Empty);
}
That's it! If you call the Strip() function and pass it an HTML-littered string then it will return an HTML-free string!

Care to Comment?

© 2010 NimbleUser • 656 Kreag Rd. Pittsford, NY 14534 • 585.586.4750
  • Twitter
  • Facebook
  • Youtube