简体   繁体   English

仅在多个空格C#上拆分

[英]Split only on multiple white spaces C#

Lets say i have a string: 让我们说我有一个字符串:

"Joe Doe     is    not    here"

I want to split this string only where it is multiple white spaces but keep the Joe Doe as one substring. 我想将此字符串拆分为多个空格,但将Joe Doe保留为一个子字符串。

So that the result would be: 结果将是:

string[] result={"Joe Doe","is","not","Here"}

使用带有@“\\ s {2,}”的Regex.Split作为模式 - 只要有2个或更多空格字符,它就会分开。

Regex.Split(input, @"\s{2,}")

This regex requires min. 这个正则表达式需要min。 2 spaces. 2个空格。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM