delete
delete

Reputation:

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.

Upvotes: 3

Views: 153

Answers (2)

m.edmondson
m.edmondson

Reputation: 30872

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)

Upvotes: 1

shybovycha
shybovycha

Reputation: 12235

Use this .Split() overload:

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

Upvotes: 6

Related Questions