Quote:
Originally Posted by rahul
Can any one help me to find out count of occurrences substring within a string.
NSString *str = @"The Quick Brown Fox Brown";
i want count of occurrence of word "Brown" from above string.
Thanks 
|
NSString *str = @"The Quick Brown Fox Brown";
NSInteger count = 0;
NSArray *arr = [str componentsSeparatedByString:@" "];
for(int i=0;i<[arr count];i++)
{
if([[arr objectAtIndex:i] isEqualToString:@"Brown"])
count++;
}