On 27/08/2009, at 9:50 AM, Peter Zegelin wrote:

I have some xml where an rgb color value is specified via a "#XXYYZZ" type string. The xml is being read in via NSXMLParser. I can't seem to find an easy Cocoa way to convert this value to an unsigned int. I need an unsigned int rather than an NSColor as the value is used in C++ code. Does anyone know of something I may be missing?


Something like this?

//assume colorString is something like @"#AABBCC"

unsigned colorCode = 0;
unsigned char redByte, greenByte, blueByte;

if (nil != colorString)
{
        NSScanner* scanner = [NSScanner scannerWithString:colorString];
        (void) [scanner scanHexInt:&colorCode];
}
redByte   = (unsigned char)(colorCode >> 16);
greenByte = (unsigned char)(colorCode >> 8);
blueByte  = (unsigned char)(colorCode);

--
Rob Keniger



_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to