How can I replace multiple spaces in a string with only one space in C#?
Example:
1 2 3 4 5
would be:
Without using regular expressions:
while (myString.IndexOf(" ", StringComparison.CurrentCulture) != -1) { myString = myString.Replace(" ", " "); }
OK to use on short strings, but will perform badly on long strings with lots of spaces.