开发者

how to concatenate values to the string

i want to cancatenate strings with comma as a separator and result must be stored in string... 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 on开发者_开发知识库e to cancatenate but is not working why?

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


Use the -componentsJoinedByString: method on NSArray:

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

(from the docs)


Cast the id types to NSString and then use the concatenation methods found in the class reference of NSString.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜