简体   繁体   English

是否可以用逗号而不是逗号分隔字符串

[英]Is it possible to split a string by comma but not by comma whitespace

I'm going trough old poorly designed comma separated data. 我将通过设计不佳的旧逗号分隔数据。 For the most part each "section" is correctly separated by a comma: 在大多数情况下,每个“部分”都正确地用逗号分隔:

string old_data = data_for_section_1,data_for_section_2,IDs|in|section|3

That is different for section 4, whose data is "comma white space" separated: 这与第4节不同,第4节的数据是“逗号空白”分隔的:

string old_data = data_for_section_1,data_for_section_2,IDs|in|section|3,section_4_part_1, section_4_part_2, section_4_part_3,data_for_section_5

Is it at all possible to get and feed the 5 sections into an array, and not end up with 7 items in that array? 是否有可能将5个部分放入一个数组中,而不是在该数组中包含7个项目?

I believe the following should work: 我相信以下应该起作用:

var data = Regex.Split(old_data, @",(?!\s)");

An example of this is here . 一个例子在这里

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

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