/* Return the range of a substring, inclusively from starting to ending delimeters Original Source: (See copyright notice at ) */ /*" Find a string from one string to another with the default options; the delimeter strings are included in the result. "*/ - (NSRange) rangeFromString:(NSString *)inString1 toString:(NSString *)inString2 { return [self rangeFromString:inString1 toString:inString2 options:0]; } /*" Find a string from one string to another with the given options inMask; the delimeter strings %are included in the result. The inMask parameter is the same as is passed to [NSString rangeOfString:options:range:]. "*/ - (NSRange) rangeFromString:(NSString *)inString1 toString:(NSString *)inString2 options:(unsigned)inMask { return [self rangeFromString:inString1 toString:inString2 options:inMask range:NSMakeRange(0,[self length])]; } /*" Find a string from one string to another with the given options inMask and the given substring range inSearchRange; the delimeter strings %are included in the result. The inMask parameter is the same as is passed to [NSString rangeOfString:options:range:]. "*/ - (NSRange) rangeFromString:(NSString *)inString1 toString:(NSString *)inString2 options:(unsigned)inMask range:(NSRange)inSearchRange { NSRange result; NSRange stringStart = NSMakeRange(inSearchRange.location,0); // if no start string, start here 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 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 (stringStart.location, NSMaxRange(stringEnd) - stringStart.location ); return result; }