Извлечение строки с помощью substringWithRange: дает «индекс вне границ»

Когда я пытаюсь извлечь строку из более крупной строки, я получаю ошибку диапазона или индекса за пределами границ. Я мог упустить из виду что-то действительно очевидное. Спасибо.

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);

ОБНОВЛЕНИЕ: 2-я часть диапазона - это длина, а не конечная точка. D'oh!

29
задан Josh Caswell 19 May 2011 в 00:11
поделиться