How can I count the occurrence of a character in a string?
Example
String: 123-456-7890
I want to find the occurrence count of \"-\
You can simply do it like this:
NSString *string = @"123-456-7890"; int times = [[string componentsSeparatedByString:@"-"] count]-1; NSLog(@"Counted times: %i", times);
Output:
Counted times: 2