Skip to content

Instantly share code, notes, and snippets.

@prabirshrestha
Created October 19, 2010 06:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save prabirshrestha/633691 to your computer and use it in GitHub Desktop.
Save prabirshrestha/633691 to your computer and use it in GitHub Desktop.
Remove Whitespace with split
// http://www.aspdotnetfaq.com/Faq/How-to-remove-duplicate-Whitespace-Characters-from-a-string.aspx
public static string RemoveWhitespaceWithSplit(string inputString)
{
StringBuilder sb = new StringBuilder();
string[] parts = inputString.Split(new [] { ' ', '\n', '\t', '\r', '\f', '\v' }, StringSplitOptions.RemoveEmptyEntries);
int size = parts.Length;
for (int i = 0; i < size; i++)
sb.AppendFormat("{0} ", parts[i]);
return sb.ToString();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment