Oyvind
Oyvind

Reputation: 65

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.

So that the result would be:

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

Upvotes: 3

Views: 987

Answers (2)

usr
usr

Reputation: 171246

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

This regex requires min. 2 spaces.

Upvotes: 4

PhonicUK
PhonicUK

Reputation: 13864

Use a Regex.Split with @"\s{2,}" as the pattern - which will split wherever there are 2 or more whitespace characters.

Upvotes: 5

Related Questions