简体   繁体   English

在逗号和空格上同时拆分字符串

[英]Split a string on comma and space at the same time

I have a string which contains comma and space . 我有一个包含逗号空格的字符串。 I need to split this string based on these two and add it into a string array. 我需要根据这两个字符串拆分此字符串并将其添加到字符串数组中。 Until now I have done it on either comma or space but not both at the same time. 到目前为止,我已经在逗号或空格中完成,但不能同时使用逗号或空格。
Here is the string: 这是字符串:

2013/02/05 11:50:57,00:00:17,5,9870,O,9851,9851,,1,1029441,0,E9870,Extn9870,E9851,GM PS,0,0,,,,,,,,,,,,, 2013/02/05 11:50:57,00:00:17,5,9870,O,9851,9851,,1,1029441,0,E9870,Extn9870,E9851,GM PS,0,0 ,,,, ,,,,,,,,,

As we can see in the above string example 2013/02/05 11:50:57 contains space and rest each one are separated by comma. 正如我们在上面的字符串示例中看到的那样2013/02/05 11:50:57包含空格和休息,每一个都用逗号分隔。

Here is the code that I have tried.. 这是我试过的代码..

 string[] str = line.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);

Just add space to the separators array? 只需在分隔符数组中添加空格?

string[] str = line.Split(new[] { ',', ' ' }, 
                                StringSplitOptions.RemoveEmptyEntries);

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

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