我的 csv 值分隔如下:
number, "This is a string, that has comma", foo, bar
这是我的 csv 阅读器:
CsvToBean<MyObject> csvToBean = new CsvToBeanBuilder<MyObject>(reader)
.withType(MyObject.class)
.withIgnoreLeadingWhiteSpace(true)
.withSeparator(',')
.withIgnoreQuotations(true)
.withSkipLines(1)
.build();
实际上会产生这些值:
number
This is a string
that has comma
foo
bar
我真正想要的是:
number
This is a string, that has comma
foo
bar
我尝试查看网站上的其他问题,但似乎它们与我的问题并不相似。那么如何仅在双引号外部用逗号分隔值并忽略双引号呢?
最佳答案
看来我只需要删除忽略引号行就可以正常工作:
CsvToBean<MyObject> csvToBean = new CsvToBeanBuilder<MyObject>(reader)
.withType(MyObject.class)
.withIgnoreLeadingWhiteSpace(true)
.withSeparator(',')
//.withIgnoreQuotations(true)
.withSkipLines(1)
.build();
关于java - Opencsv - 如何获取仅在双引号外用逗号分隔的值,同时忽略双引号?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59444169/