元素中拆分CSV和排除逗号 [英] Splitting a CSV and excluding commas within elements
本文介绍了元素中拆分CSV和排除逗号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个CSV字符串的我想把它分成数组。然而,CSV是字符串和数字的地方串用引号括起来的混合,可能包含逗号。
I've got a CSV string an I want to separate it into an array. However the CSV is a mix of strings and numbers where the strings are enclosed in quotes and may contain commas.
例如,我可能有一个CSV如下:
For example, I might have a CSV as follows:
1,"Hello",2,"World",3,"Hello, World"
我想它因此字符串被分成:
I would like it so the string is split into:
1
"Hello"
2
"World"
3
"Hello, World"
如果我用 String.Split('');
我得到:
1
"Hello"
2
"World"
3
"Hello
World"
是否有这样做的一个简单的方法?这已经写入还是我要解析由字符字符串的字符库?
Is there an easy way of doing this? A library that is already written or do I have to parse the string character by character?
推荐答案
在快速CSV阅读器文章在code项目。我用得开心很多次了。
The "A Fast CSV Reader" article on Code Project. I've used it happily many times.
这篇关于元素中拆分CSV和排除逗号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文