开发者

Convert NSMutableArray to String problem

I have got a litt开发者_Go百科le 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... :(


You should be able to do the concatenation using somewhat simpler code as below:

NSMutableString* content = [NSMutableString string];
for (int aa=0; aa < [lines2 count]; aa++){
    [content appendString:[NSString stringWithFormat:@"%@ ",[lines2 objectAtIndex:aa]]];
}

or, You could use componentsJoinedByString.


Maybe less, instead of less_or_equal?

for(int aa = 0; aa < [lines2 count]; aa++)
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜