解析csv文件 [英] parse csv file

查看:91
本文介绍了解析csv文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了解析字段中包含逗号的CSV以及字段用逗号分隔的一些问题。


例如,我在CSV中排队文件看起来像这样

 column1,column2,column3,column4 
1,00099,"Ford f250,Big Ranch",使用,Smith
1,99878,"GMC,Denalli",New,Rogers
1,4456779,"Chevy",Used,Rogers
1,99888997,"Chevy,High Country",New,Smith




我遇到的问题是字符串在第2列的逗号处拆分。我该怎么做才能删除引号, 用逗号分隔每一列,但是如果它在列本身中,则不用逗号分割?

解决方案

前几天我试过了,在福特f250,GMC等之后仍然用逗号分隔。

I'm running into some issues parsing a CSV that has commas in the field as well as the fields are separated by commas.

example, I line within the CSV file looks like this

column1, column2, column3,column4
1,00099,"Ford f250, Big Ranch",used, Smith
1,99878,"GMC, Denalli", New, Rogers
1,4456779,"Chevy", Used, Rogers
1,99888997,"Chevy, High Country", New, Smith


the issues I'm running into is that the string is splitting at the comma in column 2. What can I do to remove the quotes,  split each column at the comma, however, not split at the comma if it is in the column itself?

解决方案

I tried that the other day and still separated at the comma after Ford f250, GMC, etc.


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

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