CCNet.Build.Common.Extensions.CleanWhitespaces C# (CSharp) Method

CleanWhitespaces() public static method

Converts all whitespace characters to spaces and removes double whitespaces.
public static CleanWhitespaces ( this text ) : string
text this
return string
		public static string CleanWhitespaces(this string text)
		{
			var sb = new StringBuilder();
			bool whitespace = false;
			foreach (char c in text.Trim())
			{
				if (!Char.IsWhiteSpace(c))
				{
					whitespace = false;
					sb.Append(c);
					continue;
				}

				if (whitespace)
					continue;

				whitespace = true;
				sb.Append(' ');
			}

			return sb.ToString();
		}