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)
精彩评论