Hi All.
I would like to trim a beginning and ending double quote (") from a string. how can I achieve that in java? thanks!
Hi All.
I would like to trim a beginning and ending double quote (") from a string. how can I achieve that in java? thanks!
You can use String#replaceAll()
with a pattern of ^\"|\"$
for this.
E.g.
string = string.replaceAll("^\"|\"$", "");
To learn more about regular expressions, have al ook at http://regular-expression.info.
That said, this smells a bit like that you're trying to invent a CSV parser. If so, I'd suggest to look around for existing libraries, such as OpenCSV.
To remove the first character and last character from the string, use:
myString = myString.substring(1, myString.length()-1);