Re: Convert hexstring to int?
Re: Convert hexstring to int?
- Subject: Re: Convert hexstring to int?
- From: "Peter Karlsson" <email@hidden>
- Date: Tue, 17 Jun 2003 05:50:06 +0000
WOW!!!
This code is really a piece of art, works so good :-)) This is the way to
go!!!
Thanks a lot Prachi, and thanks to all other members that have helped me
with this as well.
Peter
From: Prachi Gauriar <email@hidden>
To: Peter Karlsson <email@hidden>
CC: email@hidden
Subject: Re: Convert hexstring to int?
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.
_________________________________________________________________
MSN 8 with e-mail virus protection service: 2 months FREE*
http://join.msn.com/?page=features/virus
_______________________________________________
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.