简体   繁体   English

如何将此字符串拆分为数组?

[英]How to split this string to an array?

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,[]],[". 我想将此字符串拆分为名为“ s2”的数组,定界符为“,0,[]],[”。 I tried with s.Split() but it only accept the delimiter is a char. 我尝试使用s.Split(),但它仅接受分隔符为char。 How I can do this? 我该怎么做? Thank you very much! 非常感谢你!

The only overloads of String.Split that accept a string as the delimiter require an array ( string[] ), so you will want this: 接受string作为定界符的String.Split的唯一重载需要一个数组( string[] ),因此您将需要以下内容:

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

See these overloads: 请参阅以下重载:

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

String.Split (String[], Int32, StringSplitOptions) String.Split(字符串[],Int32,StringSplitOptions)

希望这行得通

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

按正则表达式拆分也应该起作用。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM