Reputation: 303
I have a csv file and I'd like to precise which characters are escaping characters and which characteres aren't
My CSV file looks like this :
"Name";"Firstname";"Number"
"Johnson";"Wa;ter";"035"
"Mitchell";"James";"036"
I don't want the ; of W;lter to be treated as an escaping character and I don't to remove it either (I would prefer not to), so is it possible in Java to treat the ; like a normal character because it's outside the 2 "" ?
Thank you very much for your answers
Upvotes: 1
Views: 253
Reputation: 757
Your csv was saved using ;
as the separator, notice how "Name";"Firstname";"Number"
has ;
s separating the cells.
In csv format https://www.rfc-editor.org/rfc/rfc4180#section-2, the fields may or may not be enclosed in quotes: "Walter"
and Walter
are good. If the fields are enclosed in quotes: "Walter"
to escape a quote that is part of the field you use double quotes: "W""lter" => W"lter
. If a field contains the delimiter it must be enclosed in quotes: "W;lter"
.
Your loader might have a bug/misinterpret this so that the separator has to be escaped as well, try "W;;lter"
or "W";lter"
. Otherwise save the file with a different separator, like comma.
If the loader has a bug then it is not a good loader, try something from here: https://www.mkyong.com/java/how-to-read-and-parse-csv-file-in-java/
Upvotes: 1