Based on the code you posted with some changes, we can get to something like this:
NSRange range = NSMakeRange(0, largeString.length);
while (range.location != NSNotFound) {
NSRange icmpRange = [largeString rangeOfString:@"icmp_seq=" options:NSLiteralSearch range:range];
range.location = icmpRange.location + icmpRange.length;
range.length = largeString.length - range.location;
if (range.location != NSNotFound) {
NSRange ttlRange = [largeString rangeOfString:@" ttl" options:NSLiteralSearch range:range];
if (ttlRange.location != NSNotFound) {
NSLog(@"icmp_seq = [%@]", [largeString substringWithRange:NSMakeRange(range.location, ttlRange.location - range.location)]);
}
}
}
Keeping an updated range and using rangeOfString:options:range
, we can search only on the part of the string that we didn't search yet.