Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Removing First and Last Double Quotes

Tags:

java

string

regex

I have set of Strings 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 String.replaceAll(). I just need to remove the first and last double quotes. How can I do this?

like image 791
PeakGen Avatar asked Feb 19 '14 06:02

PeakGen


1 Answers

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)
like image 166
Hari Menon Avatar answered Sep 20 '22 19:09

Hari Menon