#import <Foundation/Foundation.h>
@interface NSString (NSStringExtend)
+ (int)numberCountOfString:(NSString *)str;
- (int)numberOfCount;
@end
@implementation NSString (NSStringExtend)
+ (int)numberCountOfString:(NSString *)str
{
return [str numberOfCount];
}
- (int)numberOfCount
{
int count = 0;
//1.把每一个字符拿出来比较
for (int i = 0; i < self.length; i++)
{
unichar c = [self characterAtIndex:i];
if (c >= '0' && c <= '9' )
{
count++;
}
}
return count;
}
@end
|
|