目标c:检查整数/整数/数字 [英] Objective c: Check if integer/int/number
本文介绍了目标c:检查整数/整数/数字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在目标c中,我如何检查字符串/ NSNumber是否为整数或int
In objective c, how can i check if a string/NSNumber is an integer or int
推荐答案
您可以使用NSString上的intValue方法:
You can use the intValue method on NSString:
NSString *myString = @"123";
[myString intValue]; // returns (int)123
以下是它的Apple文档 - 如果它是,它将返回0不是有效的整数: http://developer.apple.com/mac/library/documentation/Cocoa/Reference/Foundation/Classes/NSString_Class/Reference/NSString.html#//apple_ref/occ/instm/ NSString / intValue
Here is the Apple documentation for it - it will return 0 if it's not a valid integer: http://developer.apple.com/mac/library/documentation/Cocoa/Reference/Foundation/Classes/NSString_Class/Reference/NSString.html#//apple_ref/occ/instm/NSString/intValue
希望有所帮助!
这篇关于目标c:检查整数/整数/数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文