Strips all HTML tags from the specified string. : HTML « Network « C# / C Sharp






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);
    }

  }
}

   
  








Related examples in the same category

1.Get Links From HTML
2.Parses the value information from any INPUT tag in an HTML string where the name="" attribute matched the tagID parameter
3.Html Utilities
4.Convert HTML To Text
5.Converts a FontUnit to a size for the HTML FONT tag
6.Strip HTML
7.Remove tags from a html string
8.Sanitize any potentially dangerous tags from the provided raw HTML input using a whitelist based approach
9.Get Type As Html
10.HTML-encodes a string and returns the encoded string.
11.Removes the HTML whitespace.
12.Array To Html Breaked String
13.Show Html Page in String with Process