Reputation: 21
my input is "[/^^/]"
.
I want the output like [/^^/]
in java.
I have already tried
a.replace("\"", "")
Please help
Upvotes: 2
Views: 500
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
Reputation: 786
Try this
String s= "\"[/^^/]\"";
s = s.substring(1,s.length()-1));
System.out.println(s);
Upvotes: 1
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