CSV解析 [英] CSV Parsing

查看:147
本文介绍了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.

* =记住,有些语言环境使用[标签]在CSV的C ...

*=remember that some locales use [tab] as the C in CSV...

这篇关于CSV解析的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆