0

我想用逗号作为分隔符来连接字符串,结果必须存储在字符串中... comma=@","; for(i=0;i<[resources count];i++) { Record *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,comma,temp]; }

4

2 回答 2

5

使用-componentsJoinedByString:方法NSArray

NSArray *csvArray = [NSArray arrayWithObjects:@"here", @"be", @"dragons", nil];
NSLog(@"%@", [csvArray componentsJoinedByString:@", "]);

(来自文档

于 2010-08-14T15:29:27.593 回答
1

id类型转换为NSString然后使用在 NSString 的类引用中找到的连接方法。

于 2010-08-13T18:05:33.800 回答