Need to replace a string 11:20 with 11\:20, But when ever i try replacing the occurrences of ':' with '\:' it try escaping the '\' itself when used with "".
I don't think you're right there, but "\"s
are a royal pain in the rear in Java.
Not only are they reduced by the String class (why, I have
never understood), they are
also interpreted by the regex compiler (which takes Strings).
Furthermore, the String class isn't consistent about its
replace() methods:
replace() takes a simple String, but
replaceAll() and
replaceFirst() take regexes.
However, the simple rule is this:
Any time you want a '\' in a String you must put
at least 2 of them. If the String is
also a regex you have to put 4 (ugh!).
However, in your case
replace(":", "\\:") should do the trick.
Winston