gpt4 book ai didi

具有 '\uxxxx' 形式的 iOS 本地化 : Unicode character escape sequences, 不起作用

转载 作者:技术小花猫 更新时间:2023-10-29 10:42:21 27 4
gpt4 key购买 nike

我们在 Localization.string 文件中有键值对。

"spanish-key" = "Espa\u00f1ol";

当我们获取并分配给标签时,应用会将其显示为“Espau00f1ol”。

不起作用。

self.label1.text= NSLocalizedString(@"spanish-key", nil);

有效 - 以所需格式显示。

self.label1.text= @"Espa\u00f1ol";

我们使用的时候可能是什么问题

NSLocalizedString(@"spanish-key", nil)?

如果我们设置\U 而不是\u,那么它会起作用。

 "spanish-key" = "Espa\U00f1ol";

什么时候使用“\Uxxxx”和“\uxxxx”?

最佳答案

NSString 文字和字符串文件使用不同的转义规则

NSString 文字使用与“普通”C 字符串相同的转义序列,特别是C99 标准中定义的“通用字符名称”:

\unnnn      - the character whose four-digit short identifier is nnnn
\Unnnnnnnn - the character whose eight-digit short identifier is nnnnnnnn

例子:

NSString *string = @"Espa\u00F1ol - \U0001F600"; // Español - 😀

另一方面,字符串文件使用 \Unnnn 来表示 UTF-16 字符,和字符的“UTF-16 代理对” > U+FFFF:

"spanish-key" = "Espa\U00f1ol - \Ud83d\Ude00";

(这是“旧式属性列表”中使用的转义,打印时可以看到`NSDictionary 的描述。)

这(希望)能回答您的问题

When to use "\Uxxxx" and "\uxxxx"?

但是: @gnasher729 在他的回答中也指出,没有必要使用 Unicode转义序列。您可以简单地插入 Unicode 字符本身,在 NSString 文字和字符串文件中:

NSString *string = @"Español - 😀";

"spanish-key" = "Español - 😀";

关于具有 '\uxxxx' 形式的 iOS 本地化 : Unicode character escape sequences, 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23452906/

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