我正在开发条形码应用程序并从 CLController 获取位置,因此它给出了位置、速度和许多其他东西,所以我将 WithRange 子串化并得到异常,所以请告诉我原因,我该怎么办?
提前致谢。
- (void)locationUpdate:(CLLocation *)location {
locstr = [location description ];
//NSLog(@"current location is %@ ",locstr);
NSString* regexString =@"<(.*?)>";
NSRegularExpressionOptions options = NSRegularExpressionCaseInsensitive;
NSError* error = NULL;
NSRegularExpression* regex = [NSRegularExpression regularExpressionWithPattern:regexString options:options error:&error];
if (error) {
//NSLog(@"error is %@", [error description]);
}
NSArray* results = [regex matchesInString:locstr options:0 range:NSMakeRange(1, [locstr length])];
for (NSTextCheckingResult* result in results) {
resultString = [locstr substringWithRange:result.range];
//NSLog(@"%@",resultString);
//life = [[resultString substringWithRange:NSMakeRange(1)] retain];
resultString =[resultString substringWithRange:NSMakeRange(1,27)];
resultString = [resultString stringByReplacingOccurrencesOfString:@" "
withString:@""];
life = [resultString stringByReplacingOccurrencesOfString:@"+"
withString:@""];
life = [[life substringWithRange:NSMakeRange(0,[life length]-1)] retain];
//NSLog(@"in update %@",life);
}
}
得到这个异常
2011-11-23 14:24:58.161 BarCodeApp[2632:707] *由于未捕获的异常“NSRangeException”而终止应用程序,原因:“-[NSRegularExpression enumerateMatchesInString:options:range:usingBlock:]: Range or index out of bounds”第一掷调用堆栈:(0x326398bf 0x364a31e5 0x326397b9 0x326397db 0x3783846b 0x37838a11 0x37af 0xbe73 0x3548f5df 0x3548ef81 0x3548962f 0x3260db31 0x3260d15f 0x3260c381 0x3258f4dd 0x3258f3a5 0x37cd0fed 0x30eda743 0x2337 0x22b8)终止叫做抛出exceptionProgram接收到的信号:“SIGABRT”。数据格式化程序暂时不可用,将在“继续”后重试。(找不到 dlopen 函数,所以无法加载共享库。)