简体   繁体   中英

Objective C: uint32_t stored as String, need to read as uint32_t

I am storing color values in a database for an iPad app that needs a legend with colors in it. Each entry has it's own color value, derived from a hex value. Basically, my colors all look like this: 0X######. I have functions that can take this value, as a uint32_t, and turn it into the color I need. However, I store the value as a String.

What I need to do is convert this string to a uint32_t. I need "0X######" to equal 0X######, if that makes sense. I know this might not be possible, in which case I'll have to find another solution.

You can use NSScanner for this.

NSScanner * scanner = [NSScanner scannerWithString:@"0XAABBCC"];
uint32_t val;
[scanner scanHexLongLong:&val];

I got this code this will worked in my code,

NSScanner * scannered = [NSScanner scannerWithString:colorHex];

    uint32_t scanedVal;
    [scannered scanHexLongLong:(unsigned long long *)&scanedVal];
    NSLog(@"scanner _____%u",scanedVal);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM