iOS 判断当前字符串是否都为数字
作者:
非叼牛 | 来源:发表于
2022-10-23 10:50 被阅读0次- (BOOL)checkIsAllNumberWithString:(NSString *)string {
BOOL res = YES;
NSCharacterSet *tmpSet = [NSCharacterSet characterSetWithCharactersInString:@"0123456789"];
int i = 0;
while (i < string.length) {
NSString *str = [string substringWithRange:NSMakeRange(i, 1)];
NSRange range = [str rangeOfCharacterFromSet:tmpSet];
if (range.length == 0) {
res = NO;
break;
}
i++;
}
return res;
}
本文标题:iOS 判断当前字符串是否都为数字
本文链接:https://www.haomeiwen.com/subject/nkemzrtx.html
网友评论