简体   繁体   English

“\ 1”在此Java字符串中表示什么?

[英]What does “\1” represent in this Java string?

System.out.println("\1");

I thought it did not compile because of the non-recognized escape sequence. 我认为它没有编译,因为未识别的转义序列。

What does "\\1" exactly represent? "\\1"到底代表什么?

It's an octal escape sequence, as listed in section 3.10.6 of the JLS. 它是一个八进制转义序列,如JLS 第3.10.6节中所列 So for example: 例如:

String x = "\16";

is equivalent to: 相当于:

String x = "\u000E";

(As Octal 16 = Hex E.) (因为Octal 16 = Hex E.)

So \\1 us U+0001, the "start of heading" character. 所以\\1我们U + 0001,“标题的开始”字符。

Octal escape sequences are very rarely used in Java in my experience, and I'd personally avoid them where possible. 根据我的经验,八进制转义序列在Java中很少使用,我个人会在可能的情况下避免使用它们。 When I want to specify a character using a numeric escape sequence, I always use \\uxxxx . 当我想使用数字转义序列指定一个字符时,我总是使用\\uxxxx

在java中它是以下值

\u0001

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM