gpt4 book ai didi

iphone - 如何将 NSArray 输出连接到以逗号分隔的 NSString

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:49:31 25 4
gpt4 key购买 nike

我正在使用以下代码尝试将数组输出连接到 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com