标签:
- (NSInteger)countOfSubstring:(NSString *)substring inString:(NSString *)s
{
NSArray *ary=[s componentsSeparatedByString:substring];
NSString *str=[ary componentsJoinedByString:@""];
NSUInteger scount=s.length;
NSUInteger strcount=str.length;
NSUInteger count=(scount-strcount)/substring.length;
return count;
}
+(void)test
{
NSString *str1=@"abcaaabcccabcbbabc";
NSString *str2=@"abc";
Rten *ten=[[Rten alloc]init];
NSInteger count=[ten countOfSubstring:str2 inString:str1];
NSLog(@"出现了%ld次",(long)count);
}
标签:
原文地址:http://www.cnblogs.com/rainwz/p/4587634.html