gpt4 book ai didi

scala - 垂直制表符的字 rune 字?

转载 作者:行者123 更新时间:2023-12-03 08:37:19 26 4
gpt4 key购买 nike

如何在Scala中为垂直制表符('\v',ASCII 11)编写字 rune 字?
'\v'不起作用。 (无效的转义字符)'\11'应该是,但是...

scala> '\11'.toInt
res13: Int = 9

但是9是普通制表符('\t')的ASCII码。那里发生了什么事?

编辑:这有效并产生正确的字符,但我仍然想知道文字的语法。
val c:Char = 11

最佳答案

您需要使用'\13'。以八进制表示。

有关更多信息,请参见Scala Language Specification

1.3.4 Character Literals

Syntax:

characterLiteral ::= ‘\’’ printableChar ‘\’’ | ‘\’’ charEscapeSeq ‘\’’

A character literal is a single character enclosed in quotes. The character is either a printable unicode character or is described by an escape sequence (§1.3.6).

Example 1.3.4 Here are some character literals: ’a’ ’\u0041’ ’\n’ ’\t’ Note that ‘\u000A’ is not a valid character literal because Unicode conversion is done before literal parsing and the Unicode character \u000A (line feed) is not a printable character. One can use instead the escape sequence ‘\n’ or the octal escape ‘\12’ (§1.3.6).

关于scala - 垂直制表符的字 rune 字?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12976559/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com