How can I replace multiple spaces in a string with only one space in C#?
Example:
1 2 3 4 5
would be:
I think Matt's answer is the best, but I don't believe it's quite right. If you want to replace newlines, you must use:
myString = Regex.Replace(myString, @"\s+", " ", RegexOptions.Multiline);