Hi
I am trying search for specific text from and OCR scan.
When the text is found it works as planned.
When the text is not found I get this error.
I know it has something to do with the range but I don't see what it is.
Any help would be much appreciated.
I am trying search for specific text from and OCR scan.
When the text is found it works as planned.
When the text is not found I get this error.
Code:
*** Terminating app due to uncaught exception 'NSRangeException', reason: '-[__NSCFString substringWithRange:]: Range or index out of bounds'
*** First throw call stack:
(0x322032a3 0x39f2b97f 0x322031c5 0x32152e69 0x1d1d3 0x1c16f 0x34020ab3 0x340958ef 0x33dcac01 0x3a3424b7 0x3a3471bd 0x321d6f3b 0x32149ebd 0x32149d49 0x35d222eb 0x3405f301 0x19055 0x3a362b20)
libc++abi.dylib: terminate called throwing an exception
I know it has something to do with the range but I don't see what it is.
Code:
- (void)teststring:(NSString *)OCRText{
NSError *error = nil;
NSString *regexString = @"[A-Z]{2}[0-9]{6}[<]";
NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:regexString options:NSRegularExpressionCaseInsensitive error:&error];
NSString *match = [OCRText substringWithRange:[regex rangeOfFirstMatchInString:OCRText options:NSMatchingCompleted range:NSMakeRange(0, [OCRText length])]];
if(match == nil){
self.Message1.text = @"No passport found";
}else{
self.Message1.text = @"Passport ID found" ;
myDBControler =[databasecontrol alloc];
if([myDBControler PassportFound:[match substringWithRange:NSMakeRange(0, 8)]]){
self.Message2.text = @"Passport found in DB";
}else{
self.Message2.text = @"Passport not found in DB";
}
}
NSLog(@"Matched string: %@", [match substringWithRange:NSMakeRange(0, 8)]);
}
Any help would be much appreciated.
Last edited by a moderator: