gpt4 book ai didi

ruby - 任何人都知道字符串开头的 "weird"字符是怎么回事?

转载 作者:数据小太阳 更新时间:2023-10-29 07:03:07 26 4
gpt4 key购买 nike

我在尝试从它们的数组中检测某个字符串时遇到了一个奇怪的问题。有人知道这里发生了什么吗?

(rdb:1) p magic_string
"Time Period"
(rdb:1) p magic_string.class
String
(rdb:1) p magic_string == "Time Period"
false
(rdb:1) p "Time Period".length
11
(rdb:1) p magic_string.length
14
(rdb:1) p magic_string[0].chr
"\357"
(rdb:1) p magic_string[1].chr
"\273"
(rdb:1) p magic_string[2].chr
"\277"
(rdb:1) p magic_string[3].chr
"T"

最佳答案

您的字符串开头包含 3 个字节 (BOM),表示编码为 UTF-8。

Q: What is a BOM?

A: A byte order mark (BOM) consists of the character code U+FEFF at the beginning of a data stream, where it can be used as a signature defining the byte order and encoding form, primarily of unmarked plaintext files. Under some higher level protocols, use of a BOM may be mandatory (or prohibited) in the Unicode data stream defined in that protocol.

source

关于ruby - 任何人都知道字符串开头的 "weird"字符是怎么回事?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31388749/

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