我一直在使用斯普利特()
方法分割字符串,但这只出现,如果要拆分一个字符串的字符工作。有没有什么办法来分割字符串
,用另一个字符串被拆分由参数?我试着将分流成字符数组,没有运气。
换句话说,我想分裂字符串
:
THExxQUICKxxBROWNxxFOX
按 XX
,并返回值的数组:
的,快,布朗,FOX
解决方案为了通过一个字符串分割你将不得不使用的字符串数组超载。
字符串数据=THExxQUICKxxBROWNxxFOX;
返回data.Split(新的String [] {XX},StringSplitOptions.None);
I've been using the Split()
method to split strings, but this only appears to work if you are splitting a string by a character. Is there any way to split a string
, with another string being the split by parameter? I've tried converting the splitter into a character array, with no luck.
In other words, I'd like to split the string
:
THExxQUICKxxBROWNxxFOX
by xx
, and return an array with values:
THE, QUICK, BROWN, FOX
解决方案
In order to split by a string you'll have to use the string array overload.
string data = "THExxQUICKxxBROWNxxFOX";
return data.Split(new string[] { "xx" }, StringSplitOptions.None);