开发者

How can I use a string as a delimiter in the String.Split() method?

var playerBeginMarker = "splitHere!";开发者_如何学编程
string[] playerInfoSet = endgameStats.Split(playerBeginMarker, StringSplitOptions.None);

I'd like to split the endgameStats string, using that playerBeginMarker as the delimiter but it seems to only accept a char.


Use this .Split() overload:

Console.WriteLine("{0}", "moofoobar".Split(new string[] {"o"}, StringSplitOptions.RemoveEmptyEntries));


Use String.Split Method (String(), StringSplitOptions). You would use a String array with one element within - the string you wish to split on.

So it would be:

String[] output =  String.Split(new String[]{"splitHere!"}, StringSplitOptions.None)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜