1

I have a string:

string s = \x22thanh\\u003Cb\\u003E nien\\u003C\\/b\\u003E\x22,0,[]],[\x22thanh\\u003Cb\\u003E ca\\u003C\\/b\\u003E\x22,0,[]],[\x22thanh\\u003Cb\\u003E nhan\\u003C\\/b\\u003E\x22,0,[]],[\x22thanh\\u003Cb\\u003E thao\\u003C\\/b\\u003E\x22

I want split this string into an array named "s2", the delimiter is ",0,[]],[". I tried with s.Split() but it only accept the delimiter is a char. How I can do this? Thank you very much!

4 Answers 4

3

The only overloads of String.Split that accept a string as the delimiter require an array (string[]), so you will want this:

string[] s2 = s.Split(new string[] { ",0,[]],[" }, StringSplitOptions.RemoveEmptyEntries);

See these overloads:

String.Split (String[], StringSplitOptions)

String.Split (String[], Int32, StringSplitOptions)

Sign up to request clarification or add additional context in comments.

Comments

1

Hope this works

s.Split(new string[] {"0","[]]","[" }, StringSplitOptions.RemoveEmptyEntries);

Comments

1
string[] s2 = s.Split(new string[] { ",0,[]],[" }, StringSplitOptions.None);

Comments

0

Splitting by regular expression should work as well.

string[] s2 = Regex.Split(s, ",0,\\[\\]\\],\\[")

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.