开发者

NSStrings "containing_underscore_characters" are wrapped in quotation marks when set in NSMutableDictionary? [duplicate]

开发者 https://www.devze.com 2023-04-02 12:37 出处:网络
This question already has answers here: NSLog - Strange behavior 开发者_如何学C (2 answers) Closed 8 years ago.
This question already has answers here: NSLog - Strange behavior 开发者_如何学C (2 answers) Closed 8 years ago.

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?


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


Its just a characteristic of NSLog.

0

精彩评论

暂无评论...
验证码 换一张
取 消