将正则表达式\s+(一个或多个空格)与命名空间中的Regex.Replace方法一起使用System.Text.RegularExpressions:
s = Regex.Replace(s, @"\s+", " ");
Run Code Online (Sandbox Code Playgroud)
如果您只想替换空格,可以将" \s"更改为空格" ":
s = Regex.Replace(s, @" +", " ");
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
275 次 |
| 最近记录: |