最佳答案
假设我有一个字符串,比如:
"Hello how are you doing?"
我想要一个函数,把多个空间变成一个空间。
所以我会得到:
"Hello how are you doing?"
我知道我可以使用 regex 或调用
string s = "Hello how are you doing?".replace(" "," ");
但是我必须多次调用它,以确保所有连续的空格都只被替换为一个。
Is there already a built in method for this?