/* Return the range of a substring, searching between a starting and ending delimeters Original Source: (See copyright notice at ) */ /*" Find a string between the two given strings with the default options; the delimeter strings are not included in the result. "*/ - (NSRange) rangeBetweenString:(NSString *)inString1 andString:(NSString *)inString2 { return [self rangeBetweenString:inString1 andString:inString2 options:0]; } /*" Find a string between the two given strings with the given options inMask; the delimeter strings are not included in the result. The inMask parameter is the same as is passed to [NSString rangeOfString:options:range:]. "*/ - (NSRange) rangeBetweenString:(NSString *)inString1 andString:(NSString *)inString2 options:(unsigned)inMask { return [self rangeBetweenString:inString1 andString:inString2 options:inMask range:NSMakeRange(0,[self length])]; } /*" Find a string between the two given strings with the given options inMask and the given substring range inSearchRange; the delimeter strings are not included in the result. The inMask parameter is the same as is passed to [NSString rangeOfString:options:range:]. "*/ - (NSRange) rangeBetweenString:(NSString *)inString1 andString:(NSString *)inString2 options:(unsigned)inMask range:(NSRange)inSearchRange { NSRange result; unsigned int foundLocation = inSearchRange.location; // if no start string, start here NSRange stringEnd = NSMakeRange(NSMaxRange(inSearchRange),0); // if no end string, end here NSRange endSearchRange; if (nil != inString1) { // Find the range of the list start NSRange stringStart = [self rangeOfString:inString1 options:inMask range:inSearchRange]; if (NSNotFound == stringStart.location) { return stringStart; // not found } foundLocation = NSMaxRange(stringStart); } endSearchRange = NSMakeRange( foundLocation, NSMaxRange(inSearchRange) - foundLocation ); if (nil != inString2) { stringEnd = [self rangeOfString:inString2 options:inMask range:endSearchRange]; if (NSNotFound == stringEnd.location) { return stringEnd; // not found } } result = NSMakeRange( foundLocation, stringEnd.location - foundLocation ); return result; }