我想在C#中分割字符串方式如下:拆分C#中的字符串
传入字符串形式
string str = "[message details in here][another message here]/n/n[anothermessage here]"
,我试图把它分割成一个字符串数组形式
string[0] = "[message details in here]"
string[1] = "[another message here]"
string[2] = "[anothermessage here]"
我试图做到这一点的方式,如本
string[] split = Regex.Split(str, @"\[[^[]+\]");
但它不能正常工作这种方式,我只是得到一个空的数组或字符串
任何帮助,将不胜感激!
'但它不能正常工作这种方式 - 请具体。你是什么意思?它会抛出异常吗?它不会产生预期的结果吗?如果是这样,它会产生什么?你可以发布吗?请正确地问你的问题,否则你会在这里迅速收到投票并结束投票。 – 2013-03-14 22:48:21
使用字符串类的Split()方法重载之一。 – 2013-03-14 22:49:15
用空字符串替换所有换行符,然后拆分“] [”。 – 2013-03-14 22:49:58