Objective-c 为什么 nslog 显示双引号 " 之间的字符串”?

发布于 2024-12-01 23:02:37 字数 935 浏览 3 评论 0 原文

我正在从文本文件加载 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

I am loading a nsarray from a textfile:

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

Untitled.txt contains:

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); shows:

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

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

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

发布评论

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

评论(1

清晨说晚安 2024-12-08 23:02:37

当字符串中存在空格或其他特殊字符时,它会执行此操作。请注意,这正是 NSLog() 所做的。当您执行 [NSString stringWithFormat:...] 时,不会发生这种情况。

It does that when there are spaces or other special characters in the string. Note that this is just what NSLog() does. When you do [NSString stringWithFormat:...] this doesn't happen.

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