获取字符串在另一个字符串中出现的次数
2015-11-26 11:05 xiangjune 阅读(310) 评论(0) 编辑 收藏 举报
-(int)getAppearCount:(NSString *)withStr{
NSString *searchStr = @"#BLANK#";
int count=0;
for (int i = 0; i < withStr.length - searchStr.length + 1; i++)
{
if ([[withStr substringWithRange:NSMakeRange(i, searchStr.length)] isEqualToString:searchStr])
{
count++;
}
}
return count;
}