我真的不能像他们说的那样透过树木看到森林。首先,这是我的代码:
-(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 i = 0; i < 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;
}
}
}
}
}
代码应返回如下内容:
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:戴尔业务支持/专业支持
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:下一个工作日
2013-03-12 21:12:51.786 DellSupportApp[6254:c07] de waraiens 5:30/07/2009
但棘手的是。它只能像 10 次中的 1 次一样工作...在此函数中调用该方法:
-(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;
我觉得它进入这里显示的第一种方法非常麻烦,大约 10 次,而我只问过一次......我现在已经研究了 4 个多小时的问题,厌倦了一些错误,实际上错误主要是没有显示...
请指出我的错误...