美文网首页
判断传入的字符串是否全是0~9的数字

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

作者: 不言弃zxf | 来源:发表于2020-05-06 10:56 被阅读0次

//

+(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;

}

相关文章

网友评论

      本文标题:判断传入的字符串是否全是0~9的数字

      本文链接:https://www.haomeiwen.com/subject/wspightx.html