我需要检查一个字符是否是数字。
NSString *strTest=@"Test55";
char c =[strTest characterAtIndex:4];
我需要找出“c”是否是数字。我怎样才能在 Objective-C 中实现这个检查?
Note:返回值characterAtIndex:
不是一个char
, but a unichar
。所以这样的铸造可能很危险......
替代代码是:
NSString *strTest = @"Test55";
unichar c = [strTest characterAtIndex:4];
NSCharacterSet *numericSet = [NSCharacterSet decimalDigitCharacterSet];
if ([numericSet characterIsMember:c]) {
NSLog(@"Congrats, it is a number...");
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)