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++)
精彩评论