Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to split this string in c#?

Tags:

c#

regex

split

i'm really not used to the split string method in c# and i was wondering how come there's no split by more than one char function?

and my attempt to try to split this string below using regex has just ended up in frustration. anybody can help me?

basically i want to split the string below down to

aa**aa**bb**dd^__^a2a**a2a**b2b**dd^__^

into

aa**aa**bb**dd
a2a**a2a**b2b**dd

and then later into

aa
aa
bb
dd

a2a
a2a
b2b
dd

thanks!

like image 412
melaos Avatar asked Dec 01 '22 10:12

melaos


1 Answers

You can split using a string[]. There are several overloads.

string[] splitBy = new string[] {"^__^"};
string[] result = "aa*aa*bb*dd^__^a2a*a2a*b2b*dd^__^".Split(splitBy, StringSplitOptions.None);

// result[0] = "aa*aa*bb*dd", result[1] = "a2a*a2a*b2b*dd"
like image 187
Oded Avatar answered Dec 04 '22 15:12

Oded