11 iphone objective-c nsstring ipad
如何计算字符串中字符的出现次数?
例
字符串:123-456-7890
我想在给定的字符串中找到" - "的出现次数
Jus*_*Boo 34
你可以这样做:
NSString *string = @"123-456-7890";
int times = [[string componentsSeparatedByString:@"-"] count]-1;
NSLog(@"Counted times: %i", times);
Run Code Online (Sandbox Code Playgroud)
输出:
Counted times: 2
归档时间: |
|
查看次数: |
15530 次 |
最近记录: |