Snippet Fire

Beta
 Log In    |   Sign Up

.NET : Remove Html Tags from A String

Added on Jan-19-2012 by mikeSarg
For .NET

Tags : asp-netasp-net-mvcc#htmlregexstring

This 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).

DOWNLOAD

using System.Text.RegularExpressions; 
const string HTML_PATTERN = "<.*?>";
 
static string StripHTML (string inputString)
{
   return Regex.Replace 
     (inputString, HTML_PATTERN , " ");
}

    

Report Snippet

blog comments powered by Disqus