Removes the HTML whitespace. : HTML « Network « C# / C Sharp






Removes the HTML whitespace.

 
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 REGEX_BETWEEN_TAGS = new Regex(@">\s+", RegexOptions.Compiled);
    private static readonly Regex REGEX_LINE_BREAKS = new Regex(@"\n\s+", RegexOptions.Compiled);

    /// <summary>
    /// Removes the HTML whitespace.
    /// </summary>
    /// <param name="html">The HTML.</param>
    public static string RemoveHtmlWhitespace(string html)
    {
      if (string.IsNullOrEmpty(html))
        return string.Empty;

      html = REGEX_BETWEEN_TAGS.Replace(html, "> ");
      html = REGEX_LINE_BREAKS.Replace(html, string.Empty);

      return html.Trim();
    }

  }
}

   
  








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.Strips all HTML tags from the specified string.
12.Array To Html Breaked String
13.Show Html Page in String with Process