Possible Duplicate:
NSString is integer?
我想看看字符串是否只是数字。基本上:
if (string is integer):
#do whatever
else:
#error
我该怎么做?谢谢!
最佳答案
我使用了[NSCharacterSet十进制数字字符集]
。绝对运作良好。
NSCharacterSet* notDigits = [[NSCharacterSet decimalDigitCharacterSet] invertedSet];
if ([newString rangeOfCharacterFromSet:notDigits].location == NSNotFound)
{
// newString consists only of the digits 0 through 9
}
关于iphone - 检查 NSString 是否为 Integer,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12238221/