+ (NSArray*)rangesOfSubString:(NSString*)substring inString:(NSString*)string
{
if (substring.length == 0
|| string.length == 0) {
return nil;
}
NSMutableArray *rangeArray = [[NSMutableArray alloc] init];
NSRange searchRange = NSMakeRange(0,string.length);
NSRange foundRange;
while (searchRange.location < string.length) {
searchRange.length = string.length - searchRange.location;
foundRange = [string rangeOfString:substring options:NSCaseInsensitiveSearch range:searchRange];
if (foundRange.location != NSNotFound) {
// found an occurrence of the substring! do stuff here
searchRange.location = foundRange.location+foundRange.length;
[rangeArray addObject:[NSValue valueWithRange:foundRange]];
} else {
// no more substring to find
break;
}
}
return rangeArray;
}