【发布时间】:2011-06-19 00:21:25
【问题描述】:
以下代码将识别字符串是否为整数 - 即字符串仅包含数字。但是,我讨厌这段代码。有什么更好的方法?
NSString *mightBeAnInteger = fooString;
int intValue = [fooString intValue];
if (intValue > 0
&& [[NSString stringWithFormat:@"%d",intValue] isEqualToString:mightBeAnInteger]) {
NSLog(@"mightBeAnInteger is an integer");
}
【问题讨论】:
-
NSString is integer? 的可能重复项
标签: iphone objective-c cocoa-touch