• 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: NSString and Hexadecimal numbers
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSString and Hexadecimal numbers


  • Subject: Re: NSString and Hexadecimal numbers
  • From: Douglas Davidson <email@hidden>
  • Date: Fri, 25 May 2007 09:43:05 -0700


On May 25, 2007, at 9:22 AM, Vince Ackerman wrote:

[logText insertText:[[NSString alloc] initWithData:data encoding:NSASCIIStringEncoding]];

You could try something like this (off the top of my head, not tested):

unsigned i;
NSTextStorage *textStorage = [logText textStorage];
[textStorage beginEditing];
for (i = 0; i < [data length]; i++) {
NSString *string = [NSString stringWithFormat:@"%.2X", * ((unsigned char *)[data bytes] + i)];
[textStorage replaceCharactersInRange:NSMakeRange([text length], 0) withString:string];
}
[textStorage replaceCharactersInRange:NSMakeRange([text length], 0) withString:@"\n"];
[textStorage endEditing];


There are many other ways to do this, of course; also, when you are working directly with bytes you need to understand whether they are ordered as bytes or whether there are endianness issues.

If you are coming to WWDC, I'll be giving a talk on the Cocoa text system that will discuss (among other things) working with NSAttributedString, NSMutableAttributedString, and NSTextStorage.

Douglas Davidson

_______________________________________________

Cocoa-dev mailing list (email@hidden)

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:
This email sent to email@hidden


References: 
 >NSString and Hexadecimal numbers (From: Vince Ackerman <email@hidden>)

  • Prev by Date: Re: NSTreeController bound selection issue
  • Next by Date: GIF rotation/orientation with colorAtX:y:
  • Previous by thread: NSString and Hexadecimal numbers
  • Next by thread: "Live" support for aggregate functions (@min, @max, etc)
  • Index(es):
    • Date
    • Thread