views:

116

answers:

1

Hi,

I want to use a multidimensional array. Can any one explain how to use that in an iPhone app? I'm new to Objective-C.

Here's what I'm trying to do:

  1. I am spliting the main string on the basis of seprator and storing in an array.
  2. replacing some content of this array's each elements with new substrings and new values are storing in an new array.
  3. want to again split the each element of new array with a new seprator and want to store this new value in new array assuming this will be eassy by using multidimention.

Thanks, Aaryan

(the code I have so far)

- (void)viewDidLoad {

    [super viewDidLoad];

    NSMutableArray *arrSeprate = [[NSMutableArray alloc]init];

    NSString *temp;

    // it is a mysql query//

insertqry = @"INSERT INTO `userDecks` VALUES (1,2,618),(1,3,1471),(1,4,0),(1,5,0),(1,6,7784),(1,11,0),(1,12,469),(1,13,0),(1,16,0),(1,17,113),(1,18,0),(1,19,752),(1,20,60),(1,21,0),(1,30,0),(1,31,0),(1,32,159),(1,34,129),(1,46,143),(1,47,0),(1,53,105),(1,55,456),(1,65,0),(1,66,127),(1,67,131)";

    //step-1 ----------begin--------
        NSArray *listItems = [insertqry componentsSeparatedByString:@"),"];
    //step-1 ----------end--------
    int i=0;
    //step-2 ----------begin--------
    for (i = 1; i<[listItems count]; i++)
    {

         temp =  [listItems objectAtIndex:i];
         temp = [temp stringByReplacingOccurrencesOfString:@"(" withString:@"INSERT INTO `userInvitation` VALUES ("];
         [arrSeprate addObject:temp];
    }

//step-2 ----------end-------------

//step-3 ----------begin--------this will use the for loop to ll elemts of previous array

         NSString *middleqry = [arrSeprate objectAtIndex:0];

         NSArray *ItemsArray = [middleqry componentsSeparatedByString:@","];
         NSLog(@"%@",ItemsArray);
}
+1  A: 

Very easily, you can just add the itemsArray into the mutable array you created. This achieves the same as a multi-dimensional array. Alternatively, you can just use C multi-dimensional arrays with pointers.

Malaxeur