String.Split with string?

I probably have a very simple question.

I want to make a classic String.Split() , but with a string, not a character. Like string.Split("word") and return the array in the same way as if I did string.Split('x') .

+4
source share
2 answers

You can use String.Split(string[], StringSplitOptions options) .

The code will look like this:

 var results = theString.Split(new[] {"word"}, StringSplitOptions.None); 
+11
source

string.Split has an available overload function, but it takes an array and an enumeration.

 string test = "1Test2"; string[] results = test.Split(new string[] { "Test" }, StringSplitOptions.None); 

Returns an array containing "1" and "2".

0
source

All Articles