#import <Foundation/Foundation.h>
//OC方法
int main(int argc, const char * argv[]) {
@autoreleasepool {
NSString *str = @"sd435fbh234s523dbf";
int a = 0;
unsigned long m = 0;
for (int i = 0; i < str.length; i++) {
char c = [str characterAtIndex:i];
if (c>='0'&&c<='9') {
a++;
}
}
m = str.length - a;
NSLog(@"%ld",m);
}
return 0;
}
//C方法
#include<stdio.h>
int main()
{
char c[] = {“sd435fbh234s523dbf"};
int a = 0;
for (int i = 0; i < strlen(c); i++) {
if (c[i]>='0'&&c[i]<='9') {
a++;
}
}
printf("%d”,a);
return 0;
}
|
|