Re: NSString and Hexadecimal numbers
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