判断传入的字符串是否全是0~9的数字

2020-05-06  本文已影响0人  不言弃zxf

//

+(BOOL)stringIsNumber:(NSString *)str

{

    NSData *myD = [str dataUsingEncoding:NSUTF8StringEncoding];

    Byte *bytes = (Byte *)[myD bytes];

    //下面是Byte 转换为16进制。

    for(int i=0;i<[myD length];i++)

    {

        NSInteger hex = bytes[i]&0xff;

        if (hex < 48 || hex > 57)

        {

            return NO;

            break;

        }

    }

    return YES;

}

上一篇 下一篇

猜你喜欢

热点阅读