如果我能理解規則(請糾正我,如果我錯了):
\ 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