如何在 C# 中将字符串中的多个空格替换为一个空格?
示例:
1 2 3 4 5
转换为:
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, " ");
string sentence = "这是一个含有多个空格的句子";
RegexOptions options = RegexOptions.None;
Regex regex = new Regex("[ ]{2,}", options);
sentence = regex.Replace(sentence, " ");
标签:regex,Regex,sentence,C#,空格,RegexOptions,替换
From: https://www.cnblogs.com/xiaomandujia/p/17844609.html