iphone - 检查 NSString 是否为 Integer

标签 iphone ios sdk

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/

相关文章:

iphone - 为什么此透明图像在设备上显示为白色背景?

ios - Alamofire 错误 token (发布)与 Swift

ios - 以正确的方式上传/下载多张图片?

android - android sdk 中缺少 Cordova gradle 包装器

c++ - 适用于 C++ 的 Windows Azure SDK

iphone - Cocos2d 删除所有带有标签的Children

ios - 如何让 kGADAdSizeSmartBannerPortrait 工作

iphone - 如何仅在视频上启用旋转

ios - 以编程方式振动 Myo Armband

android - 如何使用 Spotify API 和 Spotify SDK