连接不同数组中的字符串
Concatenate strings within different arrays
我有两个数组:-
第一个数组的名字列表如下:-
NSArray *first = @[@"John",@"Brock",@"Taylor"];
第二个数组是:-
NSArray *last = @[@"Bradshaw",@"elfy",@"Swift"];
现在我需要一个全名数组。
如何连接数组中的字符串??
使用stringWithFormat
NSMutableArray *fullName = [NSMutableArray new];
for(int i=0;i<first.count;i++)
{
[fullName addObject:[NSString stringWithFormat:@"%@ %@",first[i],last[i]];
}
试试这个方法。
for(int i=0;i<first.count;i++)
{
NSLog(@"%@",[NSString stringWithFormat:@"%@ %@",[first objectAtIndex:i],[last objectAtIndex:i]]);
}
我有两个数组:-
第一个数组的名字列表如下:-
NSArray *first = @[@"John",@"Brock",@"Taylor"];
第二个数组是:-
NSArray *last = @[@"Bradshaw",@"elfy",@"Swift"];
现在我需要一个全名数组。
如何连接数组中的字符串??
使用stringWithFormat
NSMutableArray *fullName = [NSMutableArray new];
for(int i=0;i<first.count;i++)
{
[fullName addObject:[NSString stringWithFormat:@"%@ %@",first[i],last[i]];
}
试试这个方法。
for(int i=0;i<first.count;i++)
{
NSLog(@"%@",[NSString stringWithFormat:@"%@ %@",[first objectAtIndex:i],[last objectAtIndex:i]]);
}