Reputation: 1
I am reading data from a CSV file and putting the string into an array list called album
. One of the string was: The Beatles ("The White Album")
and the output when I print it using System.out.print(album.get(index))
was:
"The Beatles (""The White Album"")"
Why are there extra quotation marks at the front and last and at between?
I tried replacing the quotation of the string with \"
so that it takes quotation as a string too but the output was:
\"The Beatles (\\"The White Album\\")\
Code I tried:
System.out.print(album.get(index).replace('"','\\"');
Upvotes: 0
Views: 62
Reputation: 6969
CSV separates values with commas:
value1,value2,value3
But what if the value itself contains a comma, like say value,3
? No problem, says CSV, we'll put in in quotes:
value1,value2,"value,3"
So now the quotes are used to surround values with commas... what do we do if such a value itself contains a quote, like say, value "3"
? No problem, says CSV, we'll replace the quote with a double quote:
value1,value2,"value ""3"""
In your case, what you probably want to do is this:
"
, use it as is."
:
str.substring(1, str.length() - 1)
""
with "
Upvotes: 1