• Post Reply Bookmark Topic Watch Topic
  • New Topic

String class symbols  RSS feed

 
bob john
Ranch Hand
Posts: 116
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
String class contains some 'shortcuts'. I actually dont even know how they are called.



The "\n" jumps to new line, "\t" makes big space.

There is even more of those, for exmaple \\D, \\w...
How they are named and where I can find entire list of thems?
 
Junilu Lacar
Sheriff
Posts: 11477
180
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
They're called Escape Sequences and you can find a complete list in the JLS: https://docs.oracle.com/javase/specs/jls/se8/html/jls-3.html#jls-3.10.6

The official Tutorials also describe them: https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html under "Character and String Literals"
 
Henry Wong
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
bob john wrote:
There is even more of those, for exmaple \\D, \\w...


You are probably seeing these as part of regular expressions -- which just confuses things a bit. Basically "\D" and "\w" are predefined character classes in regular expressions.... and if you decide to hold the regex patterns in a string literal, the the backslash of these will need to be dealt with via the string escape sequences (already mentioned by Junilu).

Henry
 
bob john
Ranch Hand
Posts: 116
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes. I also seeking those regex escape sequences. I often can use them.
 
bob john
Ranch Hand
Posts: 116
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Actually found.
http://docs.oracle.com/javase/6/docs/api/java/util/regex/Pattern.html

There comes question, how to use these blocks?
Character classes [a-zA-Z].

Is it possible to use them without complex code writting, with patterns&matcher?
 
Campbell Ritchie
Marshal
Posts: 56533
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Only use \n or \r if you are told to provide the LF or CR characters. This tutorial page tells you how to use %n instead.
Regular expressions are by no means easy, but I suggest you try starting here in the Java™ Tutorials.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!