String replace a Backslash
sSource = sSource.replace("\\/", "/");
-
String
is immutable - each method you invoke on it does not change its state. It returns a new instance holding the new state instead. So you have to assign the new value to a variable (it can be the same variable) -
replaceAll(..)
uses regex. You don't need that.
Try replaceAll("\\\\", "")
or replaceAll("\\\\/", "/")
.
The problem here is that a backslash is (1) an escape chararacter in Java string literals, and (2) an escape character in regular expressions – each of this uses need doubling the character, in effect needing 4 \
in row.
Of course, as Bozho said, you need to do something with the result (assign it to some variable) and not throw it away. And in this case the non-regex variant is better.