NSString中字符的出现次数 [英] Number of Occurrences of a Character in NSString
本文介绍了NSString中字符的出现次数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个 NSString
或 NSMutableString
,并希望得到一个特定字符的出现次数。 / p>
我需要这样做相当多的字符 - 在这种情况下大写英文字符,所以它是很好的快速。
解决方案
replaceOccurrencesOfString:withString:options:range:
将返回 NSMutableString
中替换的字符数。
[string replaceOccurrencesOfString:@A
withString:@B
options:NSLiteralSearch
range:NSMakeRange(0,[receiver length])];
I have an NSString
or NSMutableString
and would like to get the number of occurrences of a particular character.
I need to do this for quite a few characters -- uppercase English characters in this case -- so it would be nice for it to be quick.
解决方案
replaceOccurrencesOfString:withString:options:range:
will return the number of characters replaced in a NSMutableString
.
[string replaceOccurrencesOfString:@"A"
withString:@"B"
options:NSLiteralSearch
range:NSMakeRange(0, [receiver length])];
这篇关于NSString中字符的出现次数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文