I have a String str=p2\7\2010 I want to check and replace if str.contains("\") then replace it into this("\\\\") instead of \. i am unable to do this in Java please give your little effort.
I have a String str=p2\7\2010 I want to check and replace if str.contains(\) then
Share
use String.replace():
You can also use
String.replaceAll(), but it uses regular expressions and so is slower in such trivial case.UPDATE:
Implementation of
String.replace()is based on regular expressions as well, but compiled in Pattern.LITERAL mode.