0
votes

I am parsing a csv using apache common csv but i am getting more records then it exists in csv that is due to in my csv i have some of the value containing record separator (\n) enclosed with double quotes.

https://commons.apache.org/proper/commons-csv/

Example:

test, "test
test 2",test 3, test 4 

I am expecting o/p as

Record 1: test
Record 2: 
test
test 2
Record 3: test 3
Record 4: test 4

But i am getting like this

Record 1: test
Record 2: test
Record 3: test 2
Record 4: test 3
Record 5: test 4

Here is the code which i am using for parsing currently.

CSVParser parser = CSVParser.parse(reader,CSVFormat.RFC4180.withFirstRecordAsHeader() .withQuote(null));

Just to add Earlier i was facing issue with having field delimiter in record field value which got resolved with .withQuote(null).

Any clue on how can we solve this?

1
Show your code. - kenny_k
We are always glad to help and support new coders but you need to help yourself first. :-) After doing more research if you have a problem post what you've tried with a clear explanation of what isn't working and provide a Minimal, Complete, and Verifiable example. Read How to Ask a good question. Be sure to take the tour and read this. - Dave
Here is the code which i am using for parsing currently. CSVParser parser = CSVParser.parse(reader, CSVFormat.RFC4180.withFirstRecordAsHeader() .withQuote(null)); Just to add Earlier i was facing issue with having field delimiter in record field value which got resolved with .withQuote(null). - piyush gajjariya

1 Answers

-1
votes

I do not see how this can work when you set the quote character to null. RFC4180 sets the quote character to double quote which is what you want here.