Objective-c – How to Concatenate String in Objective-C (iPhone)?


Possible Duplicate:
How do I concatenate strings in Objective-C?

Firstly, the platform is iPhone and label.text changes the label displayed. Consider this scenario:

I've an array of integers. And I want to display it on the screen.

Here's my take on it:

-(IBAction) updateText: (id)sender {
   int a[2];
   for (int i=0; i<=10;i++)
     label.text = [NSString stringByAppendingString: [NSString stringWithFormat: @"%i", a[i]]]; 

As you can probably see, I'm pretty confused. Pls pls help me out 🙁

Best Solution

Try this:

NSMutableString* theString = [NSMutableString string];
for (int i=0; i<=10;i++){
    [theString appendString:[NSString stringWithFormat:@"%i ",i]];
label.text = theString;