yushff

code the world。

导航

C# 中将多个空格替换成一个空格

Posted on 2013-08-30 08:23  yushff  阅读(2671)  评论(0编辑  收藏  举报
2013-04-17 15:36

C# 中如何将多个空格替换一个空格?

1
myString = Regex.Replace(myString, @"\s+", " ");

因为这段正则会获取到所有类型的空格(比如 制表符,新行等等),然后将其替换一个空格

2
RegexOptions options = RegexOptions.None;
Regex regex = newRegex(@"[ ]{2,}", options);     
tempo = regex.Replace(tempo, @" ");