开发者

Objective-C - Concatenating strings separated by pipes

I would like to loop through an array strings and add them to an NSString in the following way:

NSMutableArray *emailsArray = [[NSMutableArray alloc] initWithObjects:@"One", @"Two", @"Three", nil];

for (id email in emailsArray {
    NSString *emails = ??; 
}

So the开发者_Go百科 final NSString should be the following:

NSString *emails = @"One|Two|Three";


Use [emailsArray componentsJoinedByString:@"|"] for this.

Sample:

NSMutableArray *emailsArray = [[NSMutableArray alloc] initWithObjects:@"One", @"Two", @"Three", nil];
NSString *emails = [emailsArray componentsJoinedByString:@"|"];

Here you'll have emails = @"One|Two|Three".

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜