user3382199
user3382199

Reputation: 21

Remove starting and ending double quotes

my input is "[/^^/]".

I want the output like [/^^/] in java.

I have already tried

a.replace("\"", "")

Please help

Upvotes: 2

Views: 500

Answers (5)

swapnil7
swapnil7

Reputation: 898

Try this , this code removes only first and last occurrence of double quotes and not all occurrences of double quotes.

String input_string = "\"He said\"I am not intrested\"\"";

            String after_first_replace = input_string.replaceFirst("\"", "");

            String final_input = after_first_replace.substring(0, after_first_replace.lastIndexOf("\""));
            System.out.println(final_input);

Upvotes: 0

user508434
user508434

Reputation:

Another one:

a = a.replaceAll("^\"(.*)\"$","$1");

Upvotes: 0

Gundamaiah
Gundamaiah

Reputation: 786

Try this

String s= "\"[/^^/]\"";
s = s.substring(1,s.length()-1));
System.out.println(s);

Upvotes: 1

Florent Bayle
Florent Bayle

Reputation: 11890

String a = "\"[/^^/]\"";
a = a.replace("\"", "");
System.out.println(a);

Works for me. Don't forget that String is immutable in Java, so you have to store the result of your replace in your variable.

Upvotes: 2

Rahul Tripathi
Rahul Tripathi

Reputation: 172398

You may try this:

a= a.replaceAll("^\"|\"$", "");

Upvotes: 0

Related Questions