CSV解析 [英] CSV Parsing
本文介绍了CSV解析的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想使用C#解析CSV。如果我的标题数等于我的匹配数,我使用正则表达式找到,
并读取字符串。
I am trying to use C# to parse CSV. I used regular expressions to find ","
and read string if my header counts were equal to my match count.
现在如果我有一个值如下:这不会工作:
Now this will not work if I have a value like:
"a",""b","x","y"","c"
那么我的输出是:
'a'
'"b'
'x'
'y"'
'c'
但我想要的是:
'a'
'"b","x","y"'
'c'
有没有正则表达式或任何其他逻辑,我可以用这个?
Is there any regex or any other logic I can use for this ?
推荐答案
CSV,当处理像多行,引号,不同的分隔符*等东西 - 可能会比你想象的更棘手...也许考虑一个预滚的答案?我使用此,效果非常好。
CSV, when dealing with things like multi-line, quoted, different delimiters* etc - can get trickier than you might think... perhaps consider a pre-rolled answer? I use this, and it works very well.
* =记住某些区域设置使用[tab]作为CSV中的C ...
*=remember that some locales use [tab] as the C in CSV...
这篇关于CSV解析的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文