本帖最后由 IOS小菜鸟 于 2014-11-10 10:58 编辑
不输出空格的话我用OC试了下#import <Foundation/Foundation.h>
int main(int argc, const char * argv[]) { NSMutableString * string= @"uussi uuuyy wqkkk kkkd aaaa"; NSMutableArray * array = [NSMutableArray array]; for (int i = 0; i<[string length]; i++) { const char c = [string characterAtIndex:i]; [array insertObject:[NSNumber numberWithChar:c] atIndex:i]; //把字符串存到数组里面 }
for (int i = 0; i<26; i++) { int count = [array count]; char letter = 'a'+i; //遍历26个字母 [array removeObject:[NSNumber numberWithChar:letter]]; // 删除数组里面相应的字母比如'a'就会删除数组里面所有'a'. int count1 =count - [array count]; //得到'a'的个数 if (count1) { NSLog(@"%c %d",letter , count1); } } return 0; }
|