Question

I am helpless. I parse this text...

<parse>HELLO</parse>
<parse>World</parse>
<parse>digit</parse>
<parse>wow</parse>
<parse>hellonewitem</parse>
<parse>lastitem</parse>

with an instance of NSScanner:

    -(NSMutableArray *)parseTest
{

    if (parserTest != NULL)
    {

        NSScanner *scanner = [[NSScanner alloc] initWithString:parserTest];
        NSString *test;
        NSMutableArray *someArray = [NSMutableArray array];

        while ([scanner isAtEnd]!=YES)
        {

            [scanner scanUpToString:@"<parse>" intoString:nil];
            [scanner scanString:@"<parse>" intoString:nil];
            [scanner scanUpToString:@"</parse>" intoString:&test];
            [scanner scanString:@"</parse>" intoString:nil];


            [someArray addObject:test];

            NSLog(@"%@",test);


        }
        return someArray;
    }

Can't get my head around why I am getting the last object twice here in the returned array. What am I missing? Is there something wrong with the:

[scanner isAtEnd]!=Yes? 

Thanks for any help!

Matthias

Was it helpful?

Solution

check the count of the someArray,

NSLog(@"%d",[someArray count]);

if it is 6, then you are doing something wrong in printing the values.

else if it is 7, then something going wrong somewhere, and need to be sorted

Hope the first condition is true.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top