using System.Text;
using System.Text.RegularExpressions;

public static class StringExtensions
    public static string StripExtraSpaces(this string s)
        if (string.IsNullOrEmpty(s))
            return string.Empty;

        Regex r = new Regex(@"\s+");//remove all whitespace
        s = r.Replace(s, " ");	// to a single space

        return s;
downloadDownload PNG downloadDownload JPEG downloadDownload SVG

Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!

Click to optimize width for Twitter