什么是“\1”在这个Java字符串中表示? [英] What does "\1" represent in this Java string?

查看:2625
本文介绍了什么是“\1”在这个Java字符串中表示?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

我认为由于未识别的转义序列而无法编译。

I thought it did not compile because of the non-recognized escape sequence.

\ 1究竟代表什么?

推荐答案

这是一个八进制转义序列,如第3.10.6节。例如:

It's an octal escape sequence, as listed in section 3.10.6 of the JLS. So for example:

String x = "\16";

相当于:

String x = "\u000E";

(因为Octal 16 = Hex E。)

(As Octal 16 = Hex E.)

所以 \1 我们U + 0001,标题开头字符。

So \1 us U+0001, the "start of heading" character.

八进制逃脱根据我的经验,Java很少使用序列,我个人会在可能的情况下避免使用它们。当我想使用数字转义序列指定一个字符时,我总是使用 \uxxxx

Octal escape sequences are very rarely used in Java in my experience, and I'd personally avoid them where possible. When I want to specify a character using a numeric escape sequence, I always use \uxxxx.

这篇关于什么是“\1”在这个Java字符串中表示?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆