读取“字符串”使用 Opencsv 分隔值

发布于 2024-11-27 17:47:26 字数 293 浏览 5 评论 0原文

是否可以读取其中值由字符串而不是单个字符分隔的 csv 文件?早些时候,csv 文件有一个逗号分隔符,但现在它是使用字符串分隔符“###”创建的。我无法控制 csv 文件的创建。

我正在使用 Opencsv 库 http://sourceforge.net/projects/opencsv/ ,它确实似乎不支持仅字符串分隔符。

有办法解决以上问题吗? Opencsv 库有什么好的且类似的替代品吗?

Is it possible to read a csv file where the values are separated by a string rather than a single character? Earlier the csv file had a comma separator, but now it is being created with a string separator "###". I don't have any control over the creation of the csv file.

I'm using the Opencsv library http://sourceforge.net/projects/opencsv/ and it does not seem to have support for string separator only characters.

Is there a way to solve the above?
Are there any good and similar alternatives to the Opencsv library?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

生生不灭 2024-12-04 17:47:26

该文档为您提供了如何执行此操作的示例。请参阅http://opencsv.sourceforge.net/#custom-sepators

我可以使用自己的分隔符和引号字符吗?
是的。有些建筑商可以满足您自己的需求
分隔符和引号字符。假设您正在使用一个选项卡
分隔符,你可以这样做:

 CSVReader reader = new CSVReader(new FileReader("yourfile.csv"), '\t');

如果您单引号转义字符而不是
双引号它们,可以使用三个arg构造函数:

 CSVReader reader = new CSVReader(new FileReader("yourfile.csv"), '\t', '\'');

The docs give you an example of how to do this. See http://opencsv.sourceforge.net/#custom-sepators.

Can I use my own separators and quote characters?
Yes. There are constructors that cater for supplying your own
separator and quote characters. Say you're using a tab for your
separator, you can do something like this:

  CSVReader reader = new CSVReader(new FileReader("yourfile.csv"), '\t');

And if you single quoted your escaped characters rather than
double quote them, you can use the three arg constructor:

  CSVReader reader = new CSVReader(new FileReader("yourfile.csv"), '\t', '\'');
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文