Re: Convert hexstring to int?
Re: Convert hexstring to int?
- Subject: Re: Convert hexstring to int?
- From: Prachi Gauriar <email@hidden>
- Date: Mon, 16 Jun 2003 11:03:02 -0500
On Monday, June 16, 2003, at 03:52 AM, Peter Karlsson wrote:
>
I have a NSMutableString that looks like this:
>
>
"$00, $07, $04, $FF, $08, $FB, $0C"
>
>
Is there a simple way to convert the hexstring to several integers
>
like this?
NSScanner is an object-oriented version of scanf for the most part.
It's good for this type of thing.
NSScanner *hexScanner = [NSScanner scannerWithString:@"$00, $07, $04,
$FF, $08, $FB, $0C"];
// Cache this for later
NSCharacterSet *alphanumericCharacterSet = [NSCharacterSet
alphanumericCharacterSet];
// Keep scanning till we get to the end the string
while ([hexScanner isAtEnd] == NO) {
int scannedInt;
// Skip all characters until we find an alphanumeric character
[hexScanner scanUpToCharactersFromSet:alphanumericCharacterSet
intoString:nil];
// Read in the hex digit into an int by reference
[hexScanner scanHexInt:&scannedInt];
// Insert code to store the ints
NSLog(@"%d\n", scannedInt);
}
_______________________________________________
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.