NSLog - 奇怪的行为

发布于 2024-12-01 18:32:46 字数 313 浏览 3 评论 0原文

我发现最后一个单词用双引号显示。但为什么?

NSDictionary *guide2 = [NSDictionary dictionaryWithObjectsAndKeys:kArr, @"Kate", aArr, @"Ana-Lucia", kArr, @"John",  nil];
NSArray *array = [guide2 allKeys];
NSLog(@"%@", [array description]);

输出:

(
John,
Kate,
"Ana-Lucia"
)

I found that last word showed with double quotes. But why?

NSDictionary *guide2 = [NSDictionary dictionaryWithObjectsAndKeys:kArr, @"Kate", aArr, @"Ana-Lucia", kArr, @"John",  nil];
NSArray *array = [guide2 allKeys];
NSLog(@"%@", [array description]);

output:

(
John,
Kate,
"Ana-Lucia"
)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

压抑⊿情绪 2024-12-08 18:32:46

看来是因为Ana-Lucia键中的特殊字符-,所以它显示在双引号内。这可能是因为显示是单个单词。如果您的密钥仅包含“AnaLucia”等字母,那么它将显示不带引号的键。

如果键包含字母以外的任何字符,即使它是下划线(_)空格,该键也会显示在双引号中。

It seems that because of the special character - in the key Ana-Lucia, it displays it within double-quotes. May be this is because to show that the key is a single word. If your key contains only alphabets like "AnaLucia", then it will display it without quotes.

The key is displayed in double-quotes if it contains any characters other than alphabets, even if it is an underscore(_) or space.

凡间太子 2024-12-08 18:32:46

因为它不是严格意义上的字母数字和一个单词。尝试 NSArray *array = [NSArray arrayWithObjects:@"abc", @"123", @"$abc", @"abc", @"ab c", nil];,你会只看到前两个没有引用。这只是编写描述代码的人的实现选择。

Because it's not strictly alphanumeric and one word only. Try NSArray *array = [NSArray arrayWithObjects:@"abc", @"123", @"$abc", @"a-b-c", @"a b c", nil];, you'll see only the first two are not quoted. It's just an implementation choice from the guy who wrote the description code.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文