在Objective-C中加入阵列 [英] Join an Array in Objective-C

查看:62
本文介绍了在Objective-C中加入阵列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一种将NSMutableArray转换为字符串的方法.这种Ruby数组方法有什么可比的?

I'm looking for a method of turning a NSMutableArray into a string. Is there anything on a par with this Ruby array method?

>> array1 = [1, 2, 3]
>> array1.join(',')
=> "1,2,3"

干杯!

推荐答案

NSArray  *array1 = [NSArray arrayWithObjects:@"1", @"2", @"3", nil];
NSString *joinedString = [array1 componentsJoinedByString:@","];

componentsJoinedByString: will join the components in the array by the specified string and return a string representation of the array.

这篇关于在Objective-C中加入阵列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆