获取一个字符串在父字符串中出现次数

太感谢这位大牛啦,原文链接http://ilewen.com/questions/1154

NSUInteger cnt = 0, length = [str length]; NSRange range = NSMakeRange(0, length); while(range.location != NSNotFound) { range = [str rangeOfString: @"substr" options:0 range:range]; if(range.location != NSNotFound) { range = NSMakeRange(range.location + range.length, length - (range.location + range.length)); cnt++; } }

你可能感兴趣的:(字符串,出现次数)