NSStrings“包含下划线字符”在 NSMutableDictionary 中设置时用引号括起来?

发布于 2024-12-02 15:26:13 字数 604 浏览 0 评论 0原文

我将 NSString 添加到 NSMutableDictionary 中。有些字符串包含下划线,有些则不包含:

NSMutableDictionary *testDict = [[NSMutableDictionary alloc] init];
[testDict setObject:@"_startWithUnderscore" forKey:@"firstKey"];
[testDict setObject:@"NoUnderscore" forKey:@"secondKey"];
[testDict setObject:@"underscores_in_middle" forKey:@"thirdKey"];
NSLog(@"%@", testDict);`

OUTPUT:

firstKey = "_startWithUnderscore"; //注意添加的引号!

secondKey = NoUnderscore; //没有引号。

thirdKey = "underscores_in_middle"; //也获取引号。

呃,这是怎么回事?引号从哪里来?

I'm adding NSStrings to an NSMutableDictionary. Some strings contain an underscore, some do not:

NSMutableDictionary *testDict = [[NSMutableDictionary alloc] init];
[testDict setObject:@"_startWithUnderscore" forKey:@"firstKey"];
[testDict setObject:@"NoUnderscore" forKey:@"secondKey"];
[testDict setObject:@"underscores_in_middle" forKey:@"thirdKey"];
NSLog(@"%@", testDict);`

OUTPUT:

firstKey = "_startWithUnderscore"; //Note the added quotation marks!

secondKey = NoUnderscore; //No quotation marks.

thirdKey = "underscores_in_middle"; //Also gets quote marks.

Uh, what's going on here? Where are the quotation marks coming from?

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

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

发布评论

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

评论(2

宫墨修音 2024-12-09 15:26:14

这只是NSLog的一个特性。

Its just a characteristic of NSLog.

分分钟 2024-12-09 15:26:13
if ([[testDict objectForKey:@"firstKey"] substringWithRange:NSMakeRange(0, 1)] isEqualToString:@"_"])
{
    NSLog(@"I guess the quotes are just things that NSLog prints, definitely not actually in the NSString.");
}
if ([[testDict objectForKey:@"firstKey"] substringWithRange:NSMakeRange(0, 1)] isEqualToString:@"_"])
{
    NSLog(@"I guess the quotes are just things that NSLog prints, definitely not actually in the NSString.");
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文