How to use a string as a separator in the String.Split () method?

var playerBeginMarker = "splitHere!";
string[] playerInfoSet = endgameStats.Split(playerBeginMarker, StringSplitOptions.None);

I would like to break the endgameStats line using this playerBeginMarker as a delimiter, but it seems to only accept char.

+3
source share
2 answers

Use this overload .Split():

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

Use String.Split Method (String (), StringSplitOptions) . You should use an array Stringwith one element inside - the string you want to split.

So this will be:

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

Source: https://habr.com/ru/post/1787313/


All Articles