我正在将一个NSMutableArray复制到一个字符串。当我显示字符串时,我在数组项和数组条目之前得到一个"(“符号,其间用逗号分隔。我想逐行显示数组条目,而不是用逗号分隔。我该怎么做呢?
发布于 2012-01-05 15:04:45
有许多方法可以做到这一点。如果只想用换行符连接数组,最简单的方法是使用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);发布于 2012-01-05 15:08:28
NSMutableArray * items = someArray;
NSMutableString * bulletList = [NSMutableString stringWithCapacity:items.count*10];
for (NSString * s in items)
{
[bulletList appendFormat:@"%@\n", s];
}
yourTextView.text = bulletList;发布于 2012-01-05 15:11:09
你可以试试
NSString*str=[str1 stringByReplacingOccurrencesOfString:@"(" withString:@"\n"];这将用一个与右大括号相同的新行character.Do替换所有的左大括号。
https://stackoverflow.com/questions/8738745
复制相似问题