方法:
//获取一个字符在字符串中出现的所有位置 返回一个被NSValue包装的NSRange数组
- (NSArray *)rangeOfSubString:(NSString *)subStr inString:(NSString *)string {
if (subStr == nil && [subStr isEqualToString:@""]) {
return nil;
}
NSMutableArray *rangeArray = [NSMutableArray array];
NSString *string1 = [string stringByAppendingString:subStr];
NSString *temp;
for (int i = 0; i < string.length; i ++) {
temp = [string1 substringWithRange:NSMakeRange(i, subStr.length)];
if ([temp isEqualToString:subStr]) {
NSRange range = {i,subStr.length};
[rangeArray addObject:[NSValue valueWithRange:range]];
}
}
return rangeArray;
}