“转义序列”的含义是什么? Java 字符串文字的定义?
来自 Java 语言规范,第 3.10.5 节字符串文字:
字符可以用转义序列表示 - 一个转义序列用于 U+0000 到 U+FFFF 范围内的字符,两个转义序列用于 U+010000 到 U+10FFFF 范围内的字符的 UTF-16 代理代码单元.
这意味着什么?如果字符落在 U+0000 到 U+FFFF 范围内,则可以使用一个转义序列。一个转义序列与两个转义序列有何不同?
通过转义序列,它是否指的是 \n
、\r
等?这是一个序列还是两个转义序列?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
从 u+0000 到 u+ffff,每个数字(如果愿意的话)代表一个字符。但是,某些 unicode 字符(称为代理项对)是 u+010000 到 u+10ffff 中两个数字的组合。因此,如果您有数字 u+010000 到 u+10ffff,则需要第二个数字来表示有效字符。
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.
通过转义序列,它们意味着诸如
\u0000
之类的东西(您可以在String
文字中使用它来表示 unicode 字符)。By escape sequence, they mean stuff like
\u0000
(which you can use in aString
literal to represent a unicode character).