我正在将一个 NSMutableArray 复制到一个字符串。当我显示字符串时,我在数组项之前得到一个“(”符号,数组项之间用逗号分隔。我想逐行显示数组项,而不是用逗号分隔。我怎么能这样做
最佳答案
有很多方法可以做到这一点。如果你只想用换行符加入数组,最简单的方法是使用 NSArray
的 -componentsJoinedByString:方法。例如,要完全按照您的要求进行操作:
NSArray* myArray = // assume this exists
NSString* stringJoinedByNewLines = [myArray componentsJoinedByString:@"\n"];
// This should show each of the elements separated by a new-line (and they are now in a single string)
NSLog(@"the string: %@", stringJoinedByNewLines);
关于iphone - 将数组复制到字符串并按顺序显示字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8738745/