如何删除使用C#两个词之间的额外空间? [英] How to remove extra space between two words using C#?
本文介绍了如何删除使用C#两个词之间的额外空间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何删除使用C#两个词之间的额外空间?试想一下:
Hello World的
我想这被操纵为的Hello World
。
解决方案
RegexOptions选项= RegexOptions.None;
正则表达式的regex =新的正则表达式(@[] {2},选项);
节奏= regex.Replace(节奏,@);
甚至是:
的myString = Regex.Replace(MyString的,@\s +,);
无论是从的这里
How to remove extra space between two words using C#? Consider:
"Hello World"
I want this to be manipulated as "Hello World"
.
解决方案
RegexOptions options = RegexOptions.None;
Regex regex = new Regex(@"[ ]{2,}", options);
tempo = regex.Replace(tempo, @" ");
or even:
myString = Regex.Replace(myString, @"\s+", " ");
both pulled from here
这篇关于如何删除使用C#两个词之间的额外空间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文