我想用逗号作为分隔符来设置字符串,结果必须存储在字符串中... 逗号= @ “”; for(i = 0; i< [resources count]; i ++) { 记录* aRecord = [resources objectAtIndex:i];
temp=aRecord.programID;
if(i==0)
pid=temp;
else
//i am using this one to cancatenate but is not working why?
pid = [NSString stringWithFormat:@“%@%@%@”,pid,逗号,temp]; }
答案 0 :(得分:5)
使用-componentsJoinedByString:
上的NSArray
方法:
NSArray *csvArray = [NSArray arrayWithObjects:@"here", @"be", @"dragons", nil];
NSLog(@"%@", [csvArray componentsJoinedByString:@", "]);
(来自the docs)
答案 1 :(得分:1)
将id
类型转换为NSString
,然后使用NSString类引用中的连接方法。