NSArray *array = @[ @"22.298166 , 73.165809",
@"22.300598 , 73.167183",
@"22.298101 , 73.166188",
@"22.298128 , 73.166194",
@"22.298130 , 73.166194"];
如果您只需要知道它是否在数组内:
NSString *searchString = @"22.298130 , 73.166194";
BOOL found = [[array subarrayWithRange:NSMakeRange([array count]-3, 3)] containsObject:searchString];
NSLog(@"%@", (found) ? @"YES" : @"NO");
如果你需要知道索引,你可以做
[[array subarrayWithRange:NSMakeRange([array count]-3, 3)] enumerateObjectsUsingBlock:^(NSString *obj, NSUInteger idx, BOOL *stop) {
if ([obj isEqualToString:searchString]) {
*stop = YES; //avoid further loops, if we had a positive hit.
NSLog(@"%lu %lu", idx, [array count]-3+idx); //index in subarray and in original array
};
}];