我有这段代码:
NSString * firstdDigitTest = [numberString substringToIndex:1];
if (! [firstdDigitTest isEqualToString:@"0"])
{
numberString = [numberString substringFromIndex:1];
self.firstImageName = [namefile stringByAppendingString:firstdDigitTest];
}
self.number = [numberString integerValue];
我检查第一个数字是否不为0,如果不是0,我需要将其插入firstImageName
。但当我这样做(使用substringFromIndex
)并尝试使用integerValue时,它的工作量很大!
没有substringFromIndex
它的作品! :(
答案 0 :(得分:0)
检查[numberString intValue];
答案 1 :(得分:0)
NSString *str0 = @"XXX10098";
NSString *str1 = [str0 substringWithRange:NSMakeRange(4, str0.length-4)];
NSLog(@"%@", str1);
NSLog(@"%d", [str1 intValue]);
2012-10-28 10:52:07.309 iFoto[5652:907] 0098
2012-10-28 10:52:07.312 iFoto[5652:907] 98