我知道Java中的一些转义字符,例如:
\n : Newline
\r : Carriage return
\t : Tab
\\ : Backslash
...
有没有一个完整的清单?
\t
在此处插入一个制表符。\b
在此处插入一个退格符。\n
在此处插入一个换行符。\r
在此处插入一个回车符。\f
在此处插入一个换页符。\s
在此处插入一个空格。\'
在此处插入一个单引号。\"
在此处插入一个双引号。\\
在此处插入一个反斜杠。\a
不能编译:“非法的转义字符:String test = "\a";” - EhrykJava Escape Sequences:
\u{0000-FFFF} /* Unicode [Basic Multilingual Plane only, see below] hex value
does not handle unicode values higher than 0xFFFF (65535),
the high surrogate has to be separate: \uD852\uDF62
Four hex characters only (no variable width) */
\b /* \u0008: backspace (BS) */
\t /* \u0009: horizontal tab (HT) */
\n /* \u000a: linefeed (LF) */
\f /* \u000c: form feed (FF) */
\r /* \u000d: carriage return (CR) */
\" /* \u0022: double quote (") */
\' /* \u0027: single quote (') */
\\ /* \u005c: backslash (\) */
\{0-377} /* \u0000 to \u00ff: from octal value
1 to 3 octal digits (variable width) */
基本多语言平面是Unicode值从0x0000 - 0xFFFF(0-65535)的范围。其他平面只能通过多个字符在Java中指定:埃及象形文字A054(躺着的人)是U+1303F
/ 𓀿
,需要将其拆分为"\uD80C\uDC3F"
(UTF-16)以适用于Java字符串。其他一些语言支持更高的平面,使用"\U0001303F"
。
\u000a
似乎无法工作 -> - 无效的字符常量
在此处查看更多信息:https://dev59.com/GW865IYBdhLWcg3wU9GI - Jan\r
和\n
不同,Unicode转义序列是在编译器运行之前进行预处理的,就像你链接到的问题所指定的那样。因此,它将一个字面上的换行符插入到您的代码中,并因此失败。但是,这个转义码按照规范预期的方式“工作”。 - Ehryk\v
来表示换页符。2600 case 'v':
2601 // '\v' was implemented as VT/0x0B in releases < 1.8 (though
2602 // undocumented). In JDK8 '\v' is specified as a predefined
2603 // character class for all vertical whitespace characters.
2604 // So [-1, root=VertWS node] pair is returned (instead of a
2605 // single 0x0B). This breaks the range if '\v' is used as
2606 // the start or end value, such as [\v-...] or [...-\v], in
2607 // which a single definite value (0x0B) is expected. For
2608 // compatibility concern '\013'/0x0B is returned if
是的,以下是docs.Oracle的链接,您可以在其中找到Java中转义字符的完整列表。
转义字符始终以"\"为前缀,并用于执行某些特定任务,例如换行等。
有关转义字符的更多详细信息,请参阅以下链接:
https://docs.oracle.com/javase/tutorial/java/data/characters.html
这些是转义字符,用于操作字符串。
\t Insert a tab in the text at this point.
\b Insert a backspace in the text at this point.
\n Insert a newline in the text at this point.
\r Insert a carriage return in the text at this point.
\f Insert a form feed in the text at this point.
\' Insert a single quote character in the text at this point.
\" Insert a double quote character in the text at this point.
\\ Insert a backslash character in the text at this point.
从这里了解更多关于它们的信息。
http://docs.oracle.com/javase/tutorial/java/data/characters.html