Why double-backslash \\ for the elimination of no-digits in replaceAll()-method? 🙏
I thought:
metacharacter \D.
character \\D
Wrong?
Double-backslash?
Gelöst
Kommentare (2)
- Beliebt
- Neu
- Alt
Du musst angemeldet sein, um einen Kommentar schreiben zu können
Thomas
21 Juni, 06:59nützlich
You probably remember that String has functionaliy to represent invisible characters like tab or linebreak. To be able to write these special characters escape sequences are used. That's characters preceded by a backslash, eg. \n or \t. So a backslash followed by a character known to the system gets translated into such an invisible character.
However if a not known character is following the backslash it'll give an error and your code won't compile.
Here you do not want these special chars but you want a String representation of \D. To print a \ you need to escape it (\\). That's why you end up having to use "\\D". That will internally translate to \D.
+1
claudia
22 Juni, 11:23
Danke, Thomas! 🌟🐻🌟
+1