I have a String bo"ttle created using
String a = new String("bo\"ttle");
I want to replace the double quotes in the string with \" so that I get the output as bo\"ttle . I used the following function to do the same.
a = a.replaceAll("\"","\\\"");
But the String does not change and I still get the output as bo"ttle.
However, when I use the funtion:
a = a.replaceAll("\"","\\\\\"");
The output is bo\"ttle
Can somebody explain why the extra "\\" are required in this case?
String a = new String("bo\"ttle");
I want to replace the double quotes in the string with \" so that I get the output as bo\"ttle . I used the following function to do the same.
a = a.replaceAll("\"","\\\"");
But the String does not change and I still get the output as bo"ttle.
However, when I use the funtion:
a = a.replaceAll("\"","\\\\\"");
The output is bo\"ttle
Can somebody explain why the extra "\\" are required in this case?