当我尝试从较大的字符串中提取字符串时,它会给我一个范围或索引超出范围的错误。我可能在这里忽略了一些非常明显的东西。谢谢。
NSString *title = [TBXML textForElement:title1];
TBXMLElement * description1 = [TBXML childElementNamed:@"description" parentElement:item1];
NSString *description = [TBXML textForElement:description1];
NSMutableString *des1 = [NSMutableString stringWithString:description];
//search for <pre> tag for its location in the string
NSRange match;
NSRange match1;
match = [des1 rangeOfString: @"<pre>"];
match1 = [des1 rangeOfString: @"</pre>"];
NSLog(@"%i,%i",match.location,match1.location);
NSString *newDes = [des1 substringWithRange: NSMakeRange (match.location+5, match1.location-1)]; //<---This is the line causing the error
NSLog(@"title=%@",title);
NSLog(@"description=%@",newDes);
更新:范围的第二部分是长度,而不是端点。哦!