cocoa-touchiphone-sdk-3.0nsstringnsuinteger

NSString to NSUInteger


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


Solution

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