Elizabeth Dimova Elizabeth Dimova - 4 months ago 18
Vb.net Question

Split string by uppercase words

I have a string like the following:

HELLO: blah blah WORLD: woo woo FOO: foo foo


I need to split this string into 3 strings e.g.

HELLO: blah blah
WORLD: woo woo
FOO: foo foo


I tried to find pattern around the [:] but didn't help a lot.

Thank you.

P.S. C# or VB.NET code it's irrelevant to me. Both of these will work for me. Thx again

Answer

You can try with :--

string[] substrings = Regex.Split("HELLO: blah blah WORLD: woo woo FOO: foo foo", "(\s(?=[A-Z]))");

split the input string by space followed by capital latter.