我如何在C#中单个空格代替多个空格? [英] How do I replace multiple spaces with a single space in C#?
本文介绍了我如何在C#中单个空格代替多个空格?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何替换字符串多个空格,只有一个空间,在C#?
例如:
1 2 3 4 5
是:
1 2 3 4 5
解决方案
RegexOptions选项= RegexOptions.None;
正则表达式的regex =新的正则表达式([] {2},选项);
节奏= regex.Replace(节奏,);
How can I replace multiple spaces in a string with only one space in C#?
Example:
1 2 3 4 5
would be:
1 2 3 4 5
解决方案
RegexOptions options = RegexOptions.None;
Regex regex = new Regex("[ ]{2,}", options);
tempo = regex.Replace(tempo, " ");
这篇关于我如何在C#中单个空格代替多个空格?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文