String s=o.replace ("/","\\");
replaces "/" with "\", but what I actually need is to replace it with "\\ "instead.
How can I do so?
String s=o.replace ("/","\\");
replaces "/" with "\", but what I actually need is to replace it with "\\ "instead.
How can I do so?
you must escape each single "\", so if you want to replace a double backslash use:
String s = o.replace("/", "\\\\");
if you want to replace ALL occurences of "/" kepp the replaceAll()
-Method in mind
//EDIT:
as said in the comments, replace()
also replaces ALL occurences of the String
, but replaceAll()
can use regex.
Backslash is a reserved char and need to be escaped by one backslash:
\\
means \
, so you need 4 in your case.