• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Convert hexstring to int?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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.

References: 
 >Convert hexstring to int? (From: "Peter Karlsson" <email@hidden>)

  • Prev by Date: Re: Invisible files (was Re: Small problem)
  • Next by Date: [OT] Re: Finding a new project leader
  • Previous by thread: Re: Convert hexstring to int?
  • Next by thread: Re: Convert hexstring to int?
  • Index(es):
    • Date
    • Thread