我想遍历数组字符串,并通过以下方式将它们添加到NSString
:
NSMutableArray *emailsArray = [[NSMutableArray alloc] initWithObjects:@"One", @"Two", @"Three", nil];
for (id email in emailsArray {
NSString *emails = ??;
}
因此,最终的
NSString
应为以下内容:NSString *emails = @"One|Two|Three";
最佳答案
为此使用[emailsArray componentsJoinedByString:@"|"]
。
样品:
NSMutableArray *emailsArray = [[NSMutableArray alloc] initWithObjects:@"One", @"Two", @"Three", nil];
NSString *emails = [emailsArray componentsJoinedByString:@"|"];
在这里,您将拥有
emails = @"One|Two|Three"
。关于iphone - Objective-C-连接用管道分隔的字符串,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/5220624/