Ideally, I'd use a regular expression for this, probably something like co_2(.*?)end
, so I'd take a look at RegexKitLite as stimms suggests.
If that is not suitable, you could extract the string you're looking for with something like this:
NSString* src = @"xxxxxco_2zendxxxxxxx";
NSRange startMarker = [src rangeOfString:@"co_2"];
if (startMarker.location != NSNotFound) {
NSScanner* scanner = [NSScanner scannerWithString:src];
[scanner setScanLocation:startMarker.location + startMarker.length];
NSString* co2Value = @"";
[scanner scanUpToString:@"end" intoString:&co2Value];
NSLog(@"co_2 value is %@", co2Value);
} else {
NSLog(@"co_2 marker not found");
}
Here we look for @"co_2"
, failing if it's not found, then use an NSScanner
to grab everything from just after that string to the next occurrence of @"end"
. Note that if @"end"
is missing this code will silently grab the rest of the string.