将 NSMutableArray 转换为 String 问题
我有一个小问题。
我想使用以下代码将数组保存到文本文件中:
for(int aa = 0; aa <= [lines2 count]; aa++) {
content = [[NSString alloc] initWithFormat:@"%@;%@", content, [lines2 objectAtIndex:aa]];
}
NSString *filePath = [[NSBundle mainBundle]pathForResource:@"cart" ofType:@"txt"]; //meine Zeile
[content writeToFile:filePath atomically:NO encoding:NSStringEncodingConversionAllowLossy error:nil];
但它会使我的应用程序崩溃。任何人都可以给我一个简单的例子,如何将 NSMutable Array
从 NSMutable Array
转换
One
Two
Three
为 NSString
One;Two;Three
希望有人可以帮助我...:(
I have got a little problem.
I would like to save an array to a textfile with this code:
for(int aa = 0; aa <= [lines2 count]; aa++) {
content = [[NSString alloc] initWithFormat:@"%@;%@", content, [lines2 objectAtIndex:aa]];
}
NSString *filePath = [[NSBundle mainBundle]pathForResource:@"cart" ofType:@"txt"]; //meine Zeile
[content writeToFile:filePath atomically:NO encoding:NSStringEncodingConversionAllowLossy error:nil];
But it crashes my app. Can anybody give me an easy example, how to convert an NSMutable Array
from
One
Two
Three
to an NSString
like
One;Two;Three
Hope somebody can help me... :(
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您应该能够使用更简单的代码进行串联,如下所示:
或者,您可以使用 ComponentsJoinedByString。
You should be able to do the concatenation using somewhat simpler code as below:
or, You could use componentsJoinedByString.
也许更少,而不是 less_or_equal?
Maybe less, instead of less_or_equal?