-2

I tried using

string.replace("\","\");

But this doesn't work and gives me a compilation error

Syntax error on tokens, delete these tokens
Sotirios Delimanolis
  • 263,859
  • 56
  • 671
  • 702
Amit
  • 23
  • 1
  • 6

3 Answers3

2

Use like bellow, You need escape Special characters

string.replace("\\","\");
Abimaran Kugathasan
  • 29,154
  • 11
  • 70
  • 102
0

escape the special characters.

string.replace("\\","\");
Nambi
  • 11,766
  • 3
  • 35
  • 49
0
String p = ...;
p.replaceAll("\\\\", "\");
System.out.println(p);

use this code to replace and getting output in console..

Thanks..

Java Man
  • 1,824
  • 3
  • 20
  • 43