views:

50

answers:

2

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 one to cancatenate but is not working why?

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

+1  A: 

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

Jesse Naugher
+5  A: 

Use the -componentsJoinedByString: method on NSArray:

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

(from the docs)

quixoto
ishould have to store result in string ...
lak in iphone
@lak: Yes, this will do so. It's a method on NSArray that returns an NSString. See the documentation, or try it out.
quixoto