What is meant by “escape sequence” in the definition of Java string literals?

StackOverflow https://stackoverflow.com/questions/7459470

  •  21-01-2021
  •  | 
  •  

Pergunta

From the Java Language Specification, Section 3.10.5 String Literals:

Characters may be represented by escape sequences - one escape sequence for characters in the range U+0000 to U+FFFF, two escape sequences for the UTF-16 surrogate code units of characters in the range U+010000 to U+10FFFF.

What does this mean? If a character falls within the range U+0000 to U+FFFF, then one escape sequence may be used. How different is one escape sequence from two escape sequences?

By escape sequence, does it refer to \n, \r and similar? Are these one sequence or two escape sequences?

Foi útil?

Solução

From u+0000 to u+ffff, each number (if you will) represents a characters. However, some unicode characters (called surrogate pairs) are combination of two numbers in the u+010000 to u+10ffff. So if you have a number u+010000 to u+10ffff, then a second one is required to represent a valid character.

Outras dicas

By escape sequence, they mean stuff like \u0000 (which you can use in a String literal to represent a unicode character).

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top