-3

Possible Duplicate:
How is the code for separation of single array into two arrays?

hi all i am getting below response into single array when i used the JSON parsing from my required URL but here i have to divide single array response into three array sets one set will have TB3257,TB3259,TB3261,TB3263,TB3257,TB3260 and second array set will have TB3258,TB3260,TB3262,TB3259,TB3258 and TB3261 and third array set will have TB3258. so how is the code for dividing single array into three array sets in iphone?

(
    "    TB3257    TB3258",
    "    TB3259    TB3260",
    "    TB3261    TB3262",
    "    TB3263    TB3259",
    "    TB3257    TB3258    TB3258",
    "    TB3260    TB3261" 
)
0

1 Answer 1

4

I just tried the following code:

NSArray *yourArray = [NSArray arrayWithObjects:@"TB3257 TB3258", @"TB3259 TB3260", @"TB3261 TB3262", @"TB3263 TB3259", @"TB3257 TB3258 TB3258", @"TB3260 TB3261", nil];
NSMutableArray *firstArray = [NSMutableArray array];
NSMutableArray *secondArray = [NSMutableArray array];
NSMutableArray *thirdArray = [NSMutableArray array];
for (int i = 0; i < [yourArray count]; i++) {
    NSArray *tempArray = [[yourArray objectAtIndex:i]componentsSeparatedByString:@" "];
    [firstArray addObject:[tempArray objectAtIndex:0]];
    [secondArray addObject:[tempArray objectAtIndex:1]];
    if ([tempArray count] == 3) {
        [thirdArray addObject:[tempArray objectAtIndex:2]];
    }
}
NSLog(@"yourArray: %@\nfirst: %@\nsecond: %@\nthird: %@", yourArray, firstArray, secondArray, thirdArray);

Output was:

yourArray: (
    "TB3257 TB3258",
    "TB3259 TB3260",
    "TB3261 TB3262",
    "TB3263 TB3259",
    "TB3257 TB3258 TB3258",
    "TB3260 TB3261"
)
first: (
    TB3257,
    TB3259,
    TB3261,
    TB3263,
    TB3257,
    TB3260
)
second: (
    TB3258,
    TB3260,
    TB3262,
    TB3259,
    TB3258,
    TB3261
)
third: (
    TB3258
)

Hope it helps

Sign up to request clarification or add additional context in comments.

4 Comments

thanq for ur ANS but here i am getting some problem that is when i used it i am getting null set ur ans not applicable into my application because in my response consists space before array set values. how to avoid space to get correct set values.
@user1402718 if there's only 1 space in front you can change 0, 1 and 2 to 1, 2 and 3 respectively
i have change the code according to u but i am getting below response 2012-05-29 05:14:05.130 HpMicrosoft[1831:f803] yourArray: ( " TB3257 TB3258", " TB3259 TB3260", " TB3261 TB3262", " TB3263 TB3259", " TB3257 TB3258 TB3258", " TB3260 TB3261" ) first: ( "", "", "", "", "", "" ) second: ( "", "", "", "", "", "" ) third: ( ) how is to solve the problem.
@user1402718 post the code and output to the question

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.