How can I replace multiple spaces in a string with only one space in C#?
Example:
1 2 3 4 5
would be:
string sentence = "This is a sentence with multiple spaces"; RegexOptions options = RegexOptions.None; Regex regex = new Regex("[ ]{2,}", options); sentence = regex.Replace(sentence, " ");