-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
  • 274,122
  • 60
  • 696
  • 724
Amit
  • 23
  • 1
  • 6

3 Answers3

2

Use like bellow, You need escape Special characters

string.replace("\\","\");
Abimaran Kugathasan
  • 31,165
  • 11
  • 75
  • 105
0

escape the special characters.

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

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

Thanks..

Java Man
  • 1,854
  • 3
  • 21
  • 43