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
^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:
Post a Comment