开发者

Objective-C - Concatenating strings separated by pipes

开发者 https://www.devze.com 2023-02-15 02:33 出处:网络
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\", n

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

精彩评论

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