字符串转化NSInteger
最近需要返回NSInteger类型数据,各种判断闹心,现在做一个总结。
起始数字与字母混合
NSString *resultStr = [NSString stringWithFormat:@"34af34df"];
NSInteger index = [resultStr integerValue];
NSLog(@">>>:%ld",index);
输出:
>>>:34
起始字母与数字混合
NSString *resultStr = [NSString stringWithFormat:@"a34af34df"];
NSInteger index = [resultStr integerValue];
NSLog(@">>>:%ld",index);
输出:
>>>:0
从数组中获取对象返回NSInteger
数组中包含该对象
NSArray *testArr =[NSArray arrayWithObjects:@"a",@"b", nil];
NSInteger index = [testArr indexOfObject:@"a"];
NSLog(@">>>:%ld",index);
输出:
>>>:0
数组中不包含该对象
NSArray *testArr =[NSArray arrayWithObjects:@"a",@"b", nil];
NSInteger index = [testArr indexOfObject:@"c"];
NSLog(@">>>:%ld",index);
输出:
>>>:9223372036854775807
9223372036854775807 = 0x7FFFFFFFFFFFFFFF有符号整形最大值