views:

659

answers:

2

Hi all,

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...

Regards, dodo

A: 

you can try with [string longLongValue] or [string intValue]..

Jack
+3  A: 
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.

squelart
I think that should read `[str integerValue];`
dreamlax
D'oh! Fixed, thanks dreamlax.
squelart
A little incomplete. This won't work if the value is larger than INT_MAX. And if this is quite likely if you are using it for things like byte lengths.
Corey Floyd