I tried to replace C:\ to C$ but it is not replace when I used replace method in Java. Is replace method does not accept C:
My string shows C:\Rad\2122\Radn and how to replace C: to C$\Rad\2122\Radn in java.
I tried to replace C:\ to C$ but it is not replace when I used replace method in Java. Is replace method does not accept C:
My string shows C:\Rad\2122\Radn and how to replace C: to C$\Rad\2122\Radn in java.
I would use replaceFirst, though replace should also work.
path = path.replaceFirst("C:\\\\", "C\\$");
The \ needs to escaped twice, once in the regex and also in the String.
String path = "C:\\path";
path = path.replaceFirst("C:\\\\", "C\\$");
System.out.println(path);
prints
C$path
Try escaping the \
character
str = str.replace("C:\\", "C$");