[SalesForce] Escape backslash

I'm trying to define a string with the following value

string s = 'Something\Something';

but I got Illegal character sequence '\S' in string literal.

I tried escaping the backlash with another backlash but I ended up with a string that has two backlashes ('Something\\Something') . What am I doing wrong?

Best Answer

You need to use \\ instead \

string s = 'Something\\Something';

system.debug(s);

Output

19:13:22:003 USER_DEBUG [3]|DEBUG|Something\Something