Posted by meek
on April 12, 2007 at 11:51 PM PDT
I have string
String s = "Hello \"World\"";<br />
when i print this on console, it prints
It works fine. Now what i want to is to print
Which means i have to replace the quotes (") with (\\) and then a quote so that i may get a quote in output. so i used replaceAll method
But to my astonish, it prints out
I wondered and then tried to do it again with
Now i was able to see the desired outout i.e;
But why i have to use 5 back slashes instead of 3 which were according to the logic of "backsequences"?? I have seen the replaceAll method and it is using the pattern matching in it.
If i try to replace the string using simple "replace" method it works fine; i.e i don't have to use 5 backslashes, i use only 3 (according to logic). Can someone explain why i have to use 5 slasheds in replaceAll.