我需要从写出的数字中获取整数值,例如,在int
中从字符串@"three"
获取'3'。我怎么能这样做?
答案 0 :(得分:2)
你可以这样做:
NSString * threeString = @"three";
NSNumberFormatter *formatter = [[NSNumberFormatter alloc] init];
formatter.numberStyle = NSNumberFormatterSpellOutStyle;
formatter.locale = [NSLocale currentLocale];
NSNumber * stringNumb = [formatter numberFromString:threeString];
int threeInt = [stringNumb intValue];
NSLog(@"ThreeInt: %i", threeInt);