开发者

Convert NSMutableArray to String problem

开发者 https://www.devze.com 2023-03-06 06:07 出处:网络
I have got a litt开发者_Go百科le problem. I would like to save an array to a textfile with this code:

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

精彩评论

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