用C#中的另一个字符串分割一个字符串 [英] Split a string by another string in C#
本文介绍了用C#中的另一个字符串分割一个字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我一直在使用 Split()
方法来拆分字符串,但这仅在按字符拆分字符串时才起作用。有没有办法分割字符串
,而另一个字符串是按参数分割?
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 a 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.
换句话说,我想拆分字符串
:
THExxQUICKxxBROWNxxFOX
THExxQUICKxxBROWNxxFOX
作者 xx
,并返回一个带有值的数组:
by xx
, and return an array with values:
THE,QUICK,BROWN, FOX
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屋!
查看全文