1

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

Riscie
  • 3,775
  • 1
  • 24
  • 31

1 Answers1

0

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.

Vimal Venugopalan
  • 4,091
  • 3
  • 16
  • 25
  • Thanks for your Answer Vimal! Now this confuses me more and more. I found out that the error does not occur every time i run my program. Sometimes the array-count is 6 and everything is fine, sometimes it's 7 and `lastitem` gets displayed twice... – Riscie Sep 04 '12 at 06:06
  • Need to apologize. I found out that the error occurs in the way i fetch the string which i parse. I mark your Answer as the correct answer as it brought me to this awareness. I created a new Question to the topic here: http://stackoverflow.com/questions/12257967/pipes-in-nsstring-fetched-by-nsmutableurlrequest Thanks anyone for helping! – Riscie Sep 04 '12 at 06:36