如何在 C# 中用一个空格替换字符串中的多个空格?
例子:
1 2 3 4 5
将是:
string sentence = "This is a sentence with multiple spaces"; RegexOptions options = RegexOptions.None; Regex regex = new Regex("[ ]{2,}", options); sentence = regex.Replace(sentence, " ");