I know that backslashes are used for character escapes, so I have to use two of them to write a single backslash.
But why doesn't this compile?
"\\" => doesn't compile
BUT this:
"\\\\" => "\"
Which \ escapes what?
Thank you in advance!
I know that backslashes are used for character escapes, so I have to use two of them to write a single backslash.
But why doesn't this compile?
"\\" => doesn't compile
BUT this:
"\\\\" => "\"
Which \ escapes what?
Thank you in advance!
This depends on the context. Some String
methods don't use normal strings, they use regular expressions. In regular expressions, \
is an escape character too, so to have a regular expression that corresponds to the plain \
character, you have to write "\\\\"
.