Search code examples
androidjsonreplaceall

Replace special character "\" to "/" in json string url android


url1 = url1.replaceAll("\","/" );

This code gives error illegal line end in string literal. How to resolve this.

*


Solution

  • using "\" character is illegal in java, if you want to express backslash you should write it as double backslashes "\\" since it forms sequences with other characters which evaluates to a single character (e.g. \n = new line, \t = tab). in this case double backslash is a sequence which forms a single backslash character when evaluated.