4

I have what is probably a very simple question.

I want to do a classic String.Split(), but with a string, not a character. Like string.Split("word") and get back an array just like if I had done string.Split('x').

2 Answers 2

11

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

The code will look like:

var results = theString.Split(new[] {"word"}, StringSplitOptions.None);
Sign up to request clarification or add additional context in comments.

Comments

0

There is an available function overload on string.Split but it takes an array and an enum.

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

Will yield an array containing "1" and "2".

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.