I need to get an integer value from a written-out number, for example, get '3' in an int
from the string @"three"
. How could I do this?
Asked
Active
Viewed 88 times
0
-
(Google "parse english number" and you'll get a few ideas.) – Hot Licks May 30 '14 at 18:29
-
see this: http://stackoverflow.com/questions/15690974/convert-spelled-out-number-to-number – iamamused May 30 '14 at 18:33
1 Answers
2
You could do this:
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);

Logan
- 52,262
- 20
- 99
- 128