Reputation: 4132
I am using opencsv to read csv file. Fields are separated by comma. But in one field, if it contains quote, the comma inside the quote then is not a delimiter. For example, "Hello, World".
The current opencsv cannot deal with that. How to address this problem?
update
I found that it is not the problem of comma (so far). The problem row is:...,"a children""s heart\",...
. It seems to remove the quote, thus the read field becomes a children"s heart",......
and ......
represent all the following data.
It seems not the problem of opencsv, but mess of the input data.
Upvotes: 2
Views: 3774
Reputation: 47840
According to the documentation, you can supply custom separator and quote characters in the constructor, which should deal with it:
CSVReader(Reader reader, char separator, char quotechar)
Construct your reader with ,
as separator
and "
as quotechar
.
Upvotes: 2
Reputation: 845
You can write a custom code to search through your csv file and replace all comma's that are inside quotes with a , or a special character that you can identify later and place back as a comma.
Upvotes: 2