NSString to NSUInteger

dododedodonl picture dododedodonl · May 1, 2010 · Viewed 16.6k times · Source

I've got a number in a NSString @"15". I want to convert this to NSUInteger, but I don't know how to do that...

Answer

squelart picture squelart · May 1, 2010
NSString *str = @"15";
// Extract an integer number, returns 0 if there's no valid number at the start of the string.
NSInteger i = [str integerValue];

If you really want an NSUInteger, just cast it, but you may want to test the value beforehand.