Mega Code Archive

 
Categories / C# / Network
 

Strips all HTML tags from the specified string

using System; using System.IO; using System.Net.Mail; using System.Collections.Generic; using System.Security.Cryptography; using System.Text; using System.Text.RegularExpressions; using System.Configuration; using System.Globalization; using System.Web; using System.Web.Configuration; using System.Threading; using System.Reflection; using System.Collections; using System.Xml; using System.Net; using System.Web.Caching; namespace BlogEngine.Core {   /// <summary>   /// Utilities for the entire solution to use.   /// </summary>   public static class Utils   {     private static readonly Regex STRIP_HTML = new Regex("<[^>]*>", RegexOptions.Compiled);     /// <summary>     /// Strips all HTML tags from the specified string.     /// </summary>     /// <param name="html">The string containing HTML</param>     /// <returns>A string without HTML tags</returns>     public static string StripHtml(string html)     {       if (string.IsNullOrEmpty(html))         return string.Empty;       return STRIP_HTML.Replace(html, string.Empty);     }   } }