在NSMutableDictionary中设置NSStrings“containing_underscore_characters”时会用引号括起来吗?

时间:2011-09-02 09:19:29

标签: objective-c nsstring nsmutabledictionary

我正在将NSStrings添加到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);`

输出:

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

secondKey = NoUnderscore; //没有引号。

thirdKey = "underscores_in_middle"; //也会获得引号。

呃,这里发生了什么?引号来自哪里?

2 个答案:

答案 0 :(得分:1)

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.");
}

答案 1 :(得分:0)

它只是NSLog的一个特征。