Yo have two ways to do so.
If your string only contains the number and you are certain it is "well-written" you can just use
int i = [yourString intValue];
or floatValue
, or doubleValue
or integerValue
...
If your string is not well formatted, and you need something more powerful to extract the data, you need to use [NSNumberFormatter][1]
. For instance:
NSNumberFormatter* formatter = [[NSNumberFormatter alloc] init];
[formatter setNumberStyle:NSNumberFormatterDecimalStyle];
NSNumber* number = [formatter numberFromString:yourString];
Code is ARC.
Instances of NSNumberFormatter format the textual representation of
cells that contain NSNumber objects and convert textual
representations of numeric values into NSNumber objects. The
representation encompasses integers, floats, and doubles; floats and
doubles can be formatted to a specified decimal position.
NSNumberFormatter objects can also impose ranges on the numeric values
cells can accept.