Reputation: 8025
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!
Upvotes: 1
Views: 154
Reputation: 200233
Splitting by regular expression should work as well.
string[] s2 = Regex.Split(s, ",0,\\[\\]\\],\\[")
Upvotes: 0
Reputation: 20314
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)
Upvotes: 3
Reputation: 4463
string[] s2 = s.Split(new string[] { ",0,[]],[" }, StringSplitOptions.None);
Upvotes: 1
Reputation: 26386
Hope this works
s.Split(new string[] {"0","[]]","[" }, StringSplitOptions.RemoveEmptyEntries);
Upvotes: 1