我正在寻找一种将NSMutableArray转换为字符串的方法。有什么可以与这个Ruby数组方法相提并论的吗?
>> array1 = [1, 2, 3]
>> array1.join(',')
=> "1,2,3"
干杯!
发布于 2009-05-10 16:50:51
NSArray *array1 = [NSArray arrayWithObjects:@"1", @"2", @"3", nil];
NSString *joinedString = [array1 componentsJoinedByString:@","];
componentsJoinedByString:
将通过指定的字符串联接数组中的组件,并返回数组的字符串表示形式。
发布于 2009-05-10 16:50:57
您要查找的方法是componentsJoinedByString
。
NSArray *a = [NSArray arrayWithObjects:@"1", @"2", @"3", nil];//returns a pointer to NSArray
NSString *b = [a componentsJoinedByString:@","];//returns a pointer to NSString
NSLog(@"%@", b); // Will output 1,2,3
发布于 2009-05-10 16:51:47
NSArray *pathArray = [NSArray arrayWithObjects:@"here",
@"be", @"dragons", nil];
NSLog(@"%@",
[pathArray componentsJoinedByString:@" "]);
https://stackoverflow.com/questions/845622
复制相似问题