我正在尝试比较字符以查看它们是否匹配。我不明白为什么它不起作用。我在期待 true
在输出上,但我得到了错误。
character: "a"
word: "aardvark"
(first word) = character ; expecting true, getting false
最佳答案
所以"a"
在 Rebol 中不是字符,它实际上是一个字符串。
单个 unicode 字符是它自己的独立类型,具有自己的文字语法,例如#"a"
.例如,它可以从 INTEGER 来回转换!获得 code point , 其中单字母字符串 "a"
不能:
>> to integer! #"a"
== 97
>> to integer! "a"
** Script error: cannot MAKE/TO integer! from: "a"
** Where: to
** Near: to integer! "a"
字符串不是一系列单字符 STRING!s,而是一系列 CHAR!。所以你想要的是:
character: #"a"
word: "aardvark"
(first word) = character ;-- true!
(注意:有趣的是,单个字符串和那个字符的二进制转换是等价的:
>> to binary! "μ"
== #{CEBC}
>> to binary! #"μ"
== #{CEBC}
...那些是 UTF-8 字节表示。)
关于unicode - 比较 Rebol 3 中的字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21491827/