PeakGen PeakGen - 1 year ago 74
Java Question

Removing First and Last Double Quotes

I have set of

s where the first and last characters are double quotes. Below is an example.

String x = "‘Gravity’ tops the box office for 3rd week | New York Post"

Some other strings will contain double quotes in the middle of the text, so I can't use
. I just need to remove the first and last double quotes. How can I do this?


If the " characters are always going to be the first and last ones, you don't need a regex. Just use substring:

x = x.substring(1, x.length() - 1)