您的位置:首页 > 其它

给Nsstring增加一个对象方法:计算某个字符串中的阿拉伯数字的个数

2015-08-02 13:11 429 查看
@implementation NSString (Number)

- (int)numCount

{

    int count = 0;    

    for(int i = 0; i < self.length; i++)

    {

        unichar c = [self characterAtIndex:i];

        

        if (c > '0' && c < '9')

        {

            count++;

        }

        

    }

    return count;

}

@end

int main()

{

    int count =[@"ddjee8228jdjujwwuw8w" numCount];

    NSLog(@"%d",count);

    return 0;

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: