tags:

views:

29

answers:

2
 NSString *list = @"Norman, Stanley, Fletcher";
NSMutableArray *a2 = [[NSMutableArray alloc] init];
//a2= [list componentsSeparatedByString:@", "];


[a2 addObject:list];
//NSArray *listItems = [list componentsSeparatedByString:@", "];

NSLog(@"array is  %@",a2);
NSLog(@"array o  %@",a2[0]);

how to get a2[0]=Norman , a2[1]=stanley???

A: 

When you create a mutable array you have to add objects to the array. You can't set the mutable array equal to a normal array (its returned by componentsSeparatedByString:)

NSString *list = @"Norman, Stanley, Fletcher";
NSMutableArray *a2 = [[NSMutableArray alloc] init];
[a2 addObjectsFromArray:[list componentsSeparatedByString:@", "]];

NSLog(@"array is  %@",a2);
NSLog(@"array o  %@",[a2 objectAtIndex:0]);
Conceited Code
thanks but still a2[0]= NSCFArray??i want to get a2[0] as Norman
ram
Just changed my code above. You have to use objectAtIndex: instead of the brackets.
Conceited Code
thanks a lot :-)
ram
+1  A: 

Trying this

   NSArray *listItems = [list componentsSeparatedByString:@", "];
   [a2 addObject:list];
    NSLog(@"array o  %@", [a2 objectAtIndex:0]);
vodkhang
g8 it worked though i hav seperate issue i think i should start new thread :-)
ram