Opencsv - 如何仅在双引号外获取以逗号分隔的值,同时忽略双引号?
Opencsv - How to get values separated by commas outside double quotes only while also ignoring double quotes?
我的 csv 值分隔如下:
number, "This is a string, that has comma", foo, bar
这是我的 csv reader:
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
我试图浏览网站上的其他问题,但似乎它们与我的问题不相似。那么,如何仅在 双引号 之外通过 commas 分隔值,同时忽略双引号?
看来我只需要删除忽略引号行就可以了:
CsvToBean<MyObject> csvToBean = new CsvToBeanBuilder<MyObject>(reader)
.withType(MyObject.class)
.withIgnoreLeadingWhiteSpace(true)
.withSeparator(',')
//.withIgnoreQuotations(true)
.withSkipLines(1)
.build();
我的 csv 值分隔如下:
number, "This is a string, that has comma", foo, bar
这是我的 csv reader:
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
我试图浏览网站上的其他问题,但似乎它们与我的问题不相似。那么,如何仅在 双引号 之外通过 commas 分隔值,同时忽略双引号?
看来我只需要删除忽略引号行就可以了:
CsvToBean<MyObject> csvToBean = new CsvToBeanBuilder<MyObject>(reader)
.withType(MyObject.class)
.withIgnoreLeadingWhiteSpace(true)
.withSeparator(',')
//.withIgnoreQuotations(true)
.withSkipLines(1)
.build();