我想循环遍历一个数组字符串,并按以下方式将它们添加到NSString
:
NSMutableArray *emailsArray = [[NSMutableArray alloc] initWithObjects:@"One", @"Two", @"Three", nil];
for (id email in emailsArray {
NSString *emails = ??;
}
所以最后的NSString
应该如下:
NSString *emails = @"One|Two|Three";
答案 0 :(得分:7)
请使用[emailsArray componentsJoinedByString:@"|"]
。
样品:
NSMutableArray *emailsArray = [[NSMutableArray alloc] initWithObjects:@"One", @"Two", @"Three", nil];
NSString *emails = [emailsArray componentsJoinedByString:@"|"];
在这里,您将拥有emails = @"One|Two|Three"
。