misri
misri

Reputation: 55

Adding string Elements in NSArray

I have mutable string array named arrayout. It is having 3 element .Now I want to add 1 String element that array.But when I try to add,it is taking null value....Cant get what to do...Please help...

My code is :

       NSString *ds1 = @"--";
        [arrayout arrayByAddingObject:ds1];
        NSLog(@"arrrrr '%@'",arrayout);

Upvotes: 3

Views: 14585

Answers (3)

user1873574
user1873574

Reputation: 93

You can also do it this way:

NSMutableArray *arrayout = [[NSMutableArray alloc] init];        // alloc here
[arrayout insertObject:@"SomeText Here" atIndex:[arrayout count]];  // insert here
NSLog(@"Appended Array: '%@'",arrayout);                      // Print here

this will populate arrayout with SomeText Here.

Hope it helps!

Upvotes: 4

ChintaN -Maddy- Ramani
ChintaN -Maddy- Ramani

Reputation: 5164

Try this out:

NSString *ds1 = @"--";
[arrayout addObject:ds1];
NSLog(@"arrrrr '%@'",arrayout);

Hope this helps you.

Upvotes: 6

Legolas
Legolas

Reputation: 12325

Why are you concatenating strings like this ? You can just do something simple like

NSString* newString = [NSString stringWithFormat:@"%@/%@/%@", string1, string2, string3];

Upvotes: 2

Related Questions