objective c - NSMutableArray error, keep saying error out of bounds -


i cant see forest through trees say. first off, here code :

 -(nsmutablearray*)getwaranty:(nsstring*)string start:(nsstring*)start and:(nsstring*)end{ nsmutablearray *waranties = [[nsmutablearray alloc] init]; nsrange startrange = [string rangeofstring:start]; nsrange valuerange; valuerange.location = startrange.location + startrange.length; //beginpunt nsrange eindrange = [string rangeofstring:end]; valuerange.length = eindrange.location - valuerange.location; nsstring *result = [[nsstring alloc]init]; result = nil; if(valuerange.location != nsnotfound){     if(valuerange.length != nsnotfound){         result = [string substringwithrange:valuerange];         nsstring *testresult = [[nsstring alloc]init];         testresult = result;          nsstring* begintrim = [[nsstring alloc]init];         nsstring* begintrim1 = [[nsstring alloc]init];         nsstring* begintrim2 = [[nsstring alloc]init];         nsstring* begintrim3 = [[nsstring alloc]init];         nsstring* begintrim4 = [[nsstring alloc]init];         nsstring* begintrim5 = [[nsstring alloc]init];         nsstring* begintrim6 = [[nsstring alloc]init];         nsstring* begintrim7 = [[nsstring alloc]init];         nsstring* begintrim8 = [[nsstring alloc]init];         nsstring* begintrim9 = [[nsstring alloc]init];         nsstring* begintrim10 = [[nsstring alloc]init];         begintrim = [testresult stringbyreplacingoccurrencesofstring:@"<li class=\"toptwowarrantylistitem\">"withstring:@""];         begintrim1 = [begintrim stringbyreplacingoccurrencesofstring:@"<b>"withstring:@""];         begintrim2 = [begintrim1 stringbyreplacingoccurrencesofstring:@"<li>"withstring:@""];         begintrim3 = [begintrim2 stringbyreplacingoccurrencesofstring:@"</li>"withstring:@""];         begintrim4 = [begintrim3 stringbyreplacingoccurrencesofstring:@"</b>"withstring:@""];         begintrim5 = [begintrim4 stringbyreplacingoccurrencesofstring:@"<a href=\"javascript:selecttabfromlink(5);\" id=\"seewarrantytab\" class=\"uif_link\">"withstring:@""];         begintrim6 = [begintrim5 stringbyreplacingoccurrencesofstring:@"</a>"withstring:@""];         nsstring *lang =[[nsstring alloc]init];         lang= @"nl";         if(lang == @"nl"){             begintrim7 = [begintrim6 stringbyreplacingoccurrencesofstring:@".  raadpleeg het tabblad garantie voor meer informatie."withstring:@""];         }         begintrim8 = [begintrim7 stringbyreplacingoccurrencesofstring:@"</div>"withstring:@""];         begintrim9 = [begintrim8 stringbyreplacingoccurrencesofstring:@"\r\n"withstring:@""];         begintrim10 = [begintrim9 stringbytrimmingcharactersinset:[nscharacterset whitespaceandnewlinecharacterset]];         nsstring *warant = [[nsstring alloc]init];         nsstring *thewarant = [[nsstring alloc]init];         nsstring *hoev = [[nsstring alloc]init];         nsstring *lic = [[nsstring alloc]init];         nsstring *datum = [[nsstring alloc]init];         if(lang == @"nl"){             //split met garantie             warant = [begintrim10 stringbyreplacingoccurrencesofstring:@"  garantie met einddatum op"withstring:@""];             nsarray *array = [[nsarray alloc]init];             array = [warant componentsseparatedbystring:@"                                                                                                                 "];             nsinteger hoeveel = [array count];             if(hoeveel != 0){                 hoev = [nsstring stringwithformat:@"%d",hoeveel];                 [waranties addobject:hoev];                 for(int = 0; < hoeveel; i++){                     if([array objectatindex:i] != null){                         thewarant = [array objectatindex:i];                         nsarray *specarray = [[nsarray alloc]init];                         specarray = [thewarant componentsseparatedbystring:@"  "];                         lic = [specarray objectatindex:0];                         datum = [specarray objectatindex:1];                         [waranties addobject:lic];                         [waranties addobject:datum];                         nslog(@" de waraiens 1 :%@", [waranties objectatindex:0]);                         nslog(@" de waraiens 1 :%@", [waranties objectatindex:1]);                     }                     else{                      }                  }             nslog(@" de waraiens 1 :%@", [waranties objectatindex:0]);             nslog(@" de waraiens 2 :%@", [waranties objectatindex:1]);             nslog(@" de waraiens 3 :%@", [waranties objectatindex:2]);             nslog(@" de waraiens 4 :%@", [waranties objectatindex:3]);             nslog(@" de waraiens 5 :%@", [waranties objectatindex:4]);             return waranties;             }         }     } } 

}

the code should return somthing :

2013-03-12 21:12:51.783 dellsupportapp[6254:c07] de waraiens 1 :2

2013-03-12 21:12:51.785 dellsupportapp[6254:c07] de waraiens 2 :dell business support/prosupport

2013-03-12 21:12:51.785 dellsupportapp[6254:c07] de waraiens 3 :30/07/2009

2013-03-12 21:12:51.785 dellsupportapp[6254:c07] de waraiens 4 :next business day

2013-03-12 21:12:51.786 dellsupportapp[6254:c07] de waraiens 5 :30/07/2009

but tricky thing is. works 1 out of 10 times... method called in function :

-(nsmutablearray*) parseit: (nsstring*) topars { nsmutablearray *waranties = [[nsmutablearray alloc]init]; nsstring *begintitle = @"<title>"; nsstring *eindtitle = @"</title>"; nsstring *title = [self gettitle:topars start:begintitle and:eindtitle]; if(title != null){     nslog(@"de title = %@", title);     [waranties addobject:title];     nsstring *try = [waranties objectatindex:0];     nslog(@"de title = %@", try); }  nsstring *beginwar = @"<div class=\"toptwowarrantysummarydiv\">"; nsstring *eindwar = @"<div class=\"requestwarrantyextensiondiv\">"; nsmutablearray *warrant = [[nsmutablearray alloc]init]; warrant = [self getwaranty:topars start:beginwar and:eindwar]; if(warrant != null){     [waranties addobject:warrant];      nslog(@" de warant %@ ", [waranties objectatindex:1]); } return waranties; 

i find fisgy enters first method shown here, 10 times, while ask once... searvhin problems on 4 hours now, getting tired of erros, error not shown...

please point me errors...

looking @ code have concerns how brittle is. it's looking series of spaces separate warranties, best way split data?

besides you're making assumptions on splits. example:

specarray = [thewarant componentsseparatedbystring:@"  "]; 

is assigned , check both index 0 , 1, never make sure there 2 values in array.

your nslogs @ bottom don't check array bounds before they're processed.

spaces make notoriously bad delimiters data. if you're looking parse html there tools out there might job better.


Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -