如何正确解析CSV文件到2d阵列? [英] How to properly parse CSV file to 2d Array?

查看:163
本文介绍了如何正确解析CSV文件到2d阵列?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图将csv文件解析为2d数组,其中每一行都是一个数据条目,每一列都是该条目中的一个字段。

I'm trying to parse a csv file into a 2d array, where each row is a data entry and each column is a field in that entry.

我试着写一个简单的解析器,使用 String.Split

I tried to write a simple parser that used String.Split to separate file by commas. This is a horrible approach as I have discovered. It completely fails to parse any special cases like double quotes, line feeds, and other special chars.

将CSV文件解析为2d数组的正确方法是我已经描述过了吗?

What is the proper way to parse a CSV file into a 2d array as I have described?

Java中的代码示例将不胜感激。
数组可以是一个动态列表对象或向量或类似的东西,它只需要两个索引器可索引。

Code samples in Java would be appreciated. The array can be a dynamic list object or vector or something like that, it just has to be indexable with two indexers.

推荐答案

为什么不使用库?
例如: http://opencsv.sourceforge.net/#在哪里可以得到它

这篇关于如何正确解析CSV文件到2d阵列?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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