我正在使用以下代码尝试将数组输出连接到 NSString。
NSArray *array1 = [NSArray arrayWithObjects:[item objectForKey:@"id"], nil];
NSString *joinedString = [array1 componentsJoinedByString:@","];
NSLog(@"joinedString is %@", joinedString);
我希望将连接后的字符串输出为:连接后的字符串为 55,56,57,66,88...等等...目前输出为:
2013-03-05 13:13:17.052 [63705:907] joinedString is 55
2013-03-05 13:13:17.056 [63705:907] joinedString is 56
2013-03-05 13:13:17.060 [63705:907] joinedString is 57
2013-03-05 13:13:17.064 [63705:907] joinedString is 66
最佳答案
您可能在循环中运行 join 方法。
我想这就是你想要的。
NSMutableArray * array1 = [NSMutableArray array]; // create a Mutable array
for(id item in items){
[array1 addObject:[item objectForKey:@"id"]]; // Add the values to this created mutable array
}
NSString *joinedString = [array1 componentsJoinedByString:@","];
NSLog(@"joinedString is %@", joinedString);
关于iphone - 如何将 NSArray 输出连接到以逗号分隔的 NSString,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15224731/