Re: Convert hexadecimal NSString (0xff00) to decimal integer?
Re: Convert hexadecimal NSString (0xff00) to decimal integer?
- Subject: Re: Convert hexadecimal NSString (0xff00) to decimal integer?
- From: "Clark S. Cox III" <email@hidden>
- Date: Tue, 7 Jan 2003 11:38:58 -0500
On Tuesday, Jan 7, 2003, at 11:20 US/Eastern, Daniel Ericsson wrote:
On tisdag, jan 7, 2003, at 14:54 Europe/Stockholm, Greg Hurrell wrote:
Perhaps it's bleedingly obvious and staring me in the face, but I
couldn't find any shortcuts in NSString or NSNumber that might do
this conversion in one hit... and I find that odd because Apple
obviously has code which does this (if you look at the way their code
can parse plists it's evident they have plenty of tricks for
converting between various types of strings and numbers etc).
I agree, for completeness sake, there should be a way to get an
integer from a hexadecimal NSString using the Cocoa frameworks (if
it's there I can't see it either).
You could use NSScanner:
{
unsigned result;
if([[NSScanner scannerWithString: aString] scanHexInt: &result])
NSLog(@"Conversion succeeded: %u", result);
else
NSLog(@"Conversion failed");
}
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.