如果我能理解规则(请纠正我,如果我错了):
\ OctalDigit
Examples:
\0, \1, \2, \3, \4, \5, \6, \7
\ OctalDigit OctalDigit
Examples:
\00, \07, \17, \27, \37, \47, \57, \67, \77
\ ZeroToThree OctalDigit OctalDigit
Examples:
\000, \177, \277, \367,\377
\t
,\n
,\\
不要下OctalEscape规则回落;他们必须在单独的转义字符规则下。
十进制255等于八进制377(使用Windows计算器在科学模式确认)
因此,一个三位数的八进制值落入的\000
(0)到\377
(255)
范围因此,\4715
不是有效的八进制值,因为它超过三位八进制数规则。如果要访问带有十进制值4715的代码点字符,请使用Unicode转义符号\u
来表示UTF-16字符\u126B
(4715以十进制形式),因为每个Java char
都采用Unicode UTF-16。
从http://docs.oracle.com/javase/1.5.0/docs/api/java/lang/Character.html:
The char data type (and therefore the value that a Character object encapsulates) are based on the original Unicode specification, which defined characters as fixed-width 16-bit entities. The Unicode standard has since been changed to allow for characters whose representation requires more than 16 bits. The range of legal code points is now U+0000 to U+10FFFF, known as Unicode scalar value. (Refer to the definition of the U+n notation in the Unicode standard.)
The set of characters from U+0000 to U+FFFF is sometimes referred to as the Basic Multilingual Plane (BMP). Characters whose code points are greater than U+FFFF are called supplementary characters. The Java 2 platform uses the UTF-16 representation in char arrays and in the String and StringBuffer classes. In this representation, supplementary characters are represented as a pair of char values, the first from the high-surrogates range, (\uD800-\uDBFF), the second from the low-surrogates range (\uDC00-\uDFFF).
被修改:
凡是超过8位范围(大于一个字节)的有效八进制值是语言特定的。有些编程语言可能会继续匹配Unicode实现;有些可能不会(限制为一个字节)。 Java绝对不允许它,即使它具有Unicode支持。
一些编程语言(供应商相关),该限制一字节八进制文字:
- 的Java(所有的供应商): - 以0或单位中开始八进制整数常数基数为8(高达0377); \ 0到\ 7,\ 00到\ 77,\ 000到\ 377(八进制字符串文本格式)
- C/C++(Microsoft) - 以0开头的八进制整数常量(最多0377);八进制字符串文字格式
\nnn
- Ruby - 以0开头的八进制整数常量(最多0377);八进制字符串文字格式
\nnn
一些编程语言(供应商相关),支持高于一字节较大八进制文字:
- Perl的 - 即从0开始一个八进制整数常数;八进制字符串文字格式
\nnn
见http://search.cpan.org/~jesse/perl-5.12.1/pod/perlrebackslash.pod#Octal_escapes
不支持八进制文字一些编程语言:
- C# - 使用
Convert.ToInt32(integer, 8)
为基8 How can we convert binary number into its octal number using c#?
255是基本的ASCII限制,如果我没有弄错,那么每个基本的ASCII字符都有一个。你不应该为此感到高兴吗? \ 4715之所以不能上去,是因为它超过了255,这是标准的ASCII限制= D(我不善于解释,指的是回答者) – 2012-03-03 03:47:19
@Shingetsu:ASCII限制是127,而不是255 。_Bytes_被限制为255,除非你在谈论Java字节,由于一些奇怪的原因,它们被签名为:-)但是Java字符不是字节。 – paxdiablo 2012-03-03 04:30:43
[另见](http://stackoverflow.com/questions/3537706/howto-unescape-a-java-string-literal-in-java/4298836) – 2014-04-02 01:11:07