Wednesday, May 7, 2014

How to remove quotes from the string usig java

String replaceFirst method comes handy for removing quotes.
^regex - Finds regex that must match at the beginning of the line
regex$ - Finds regex that must match at the end of the line.

so you can use like below,
for eg,

                String withQuotes = "\"get me without quotes\"";
System.out.println("With Quotes="+withQuotes);
System.out.println("Without Quotes="+withQuotes.replaceFirst("^\"", "").replaceFirst("\"$", ""));

It prints,
With Quotes="get me without quotes"
Without Quotes=get me without quotes

No comments: