objective-c为什么nslog在双引号“”之间显示字符串?

时间:2011-08-29 14:19:41

标签: objective-c nsarray nslog

我正在从文本文件加载nsarray:

NSArray *noWords = [[NSArray alloc] initWithArray:
                        [[NSString stringWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"untitled" ofType:@"txt"]
                                                   encoding:NSUTF8StringEncoding error:NULL] componentsSeparatedByString:@"\n"]];

Untitled.txt包含:

alfa
beta (geologi).
beta
jaha
javel
jam (geologi) en
jamen
jamen
jamen
jax. (geologi)jammen
det
var
æhæhæ
øhøh
på
tide
.(geologi),be;ta;
tiden
men
but
men
aha
beta

NSLog(@“noWords:%@”,noWords);所示:

2011-08-29 16:16:44.288 scanner2[30177:207] noWords : (
alfa,
"beta (geologi).",
beta,
jaha,
javel,
"jam (geologi) en",
jamen,
jamen,
jamen,
"jax. (geologi)jammen",
det,
var,
"\U00e6h\U00e6h\U00e6",
"\U00f8h\U00f8h",
"p\U00e5",
tide,
".(geologi),be;ta;",
tiden,
men,
but,
men,
aha,
beta

1 个答案:

答案 0 :(得分:3)

当字符串中有空格或其他特殊字符时,它会这样做。请注意,这正是NSLog()所做的。当你执行[NSString stringWithFormat:...]时,这不会发生。