如何将值连接到字符串

Lin*_*rld 0 iphone xcode string-concatenation

我想用逗号作为分隔符来设置字符串,结果必须存储在字符串中... 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?
Run Code Online (Sandbox Code Playgroud)

pid = [NSString stringWithFormat:@"%@%@%@",pid,逗号,temp]; }

Ben*_*tto 5

使用-componentsJoinedByString:方法NSArray:

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

(来自文档)