C#字符串分割到另一个字符串 [英] C# Split A String By Another String
问题描述
我一直在使用斯普利特()
方法分割字符串,但这只出现,如果要拆分一个字符串的字符工作。有没有什么办法来分割字符串
,用另一个字符串被拆分由参数?我试着将分流成字符数组,没有运气。
换句话说,我想分裂字符串
:
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);
这篇关于C#字符串分割到另一个字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!