如何使用Regex将给定的字符串拆分为多个部分 [英] how to split given string into parts with Regex
本文介绍了如何使用Regex将给定的字符串拆分为多个部分的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
给出:@[29,33,4,3],true,'',3,'en'
需要接收包含{@[29,33]的字符串[] ,4,3],@true,@'',3,'en'}
除以','得到错误的结果
解决方案
虽然你可以使用正则表达式,但它可能不是最好的解决方案 - 我会考虑使用CSV阅读器并对其进行修改以支持你的'[',']'对以及正常的报价。
这是一个很好的报价: A快速CSV阅读器 [ ^ 一>
given: @"[29,33,4,3],true,'', 3, 'en'"
need to recieve string[] containing { @"[29,33,4,3]", @"true", @"''", "3", "'en'" }
split by ',' gives wrong result
解决方案
Although you could use a Regex, it probably isn't the best solution - I'd look at taking a CSV reader and modifying it to support your '[',']' pairs as well as the normal quotes.
This is a good one: A Fast CSV Reader[^]
这篇关于如何使用Regex将给定的字符串拆分为多个部分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文