[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Getting a numerical rep of every byte of a UTF-8 string?
From: |
Helge Hess |
Subject: |
Re: Getting a numerical rep of every byte of a UTF-8 string? |
Date: |
Wed, 17 Mar 2004 22:25:59 +0100 |
On 17.03.2004, at 22:02, Christopher Culver wrote:
If I have char * utf8String = [singleCharNSString UTF8String], how can
I get each byte of utf8String and display it as a hex number e.g.
0x53? If anyone could show me working code, I would be most grateful.
Treating it as a normal C string doesn't seem to work. Once I see how
it's done I should be able to adapt it to displaying UTF-8 as octal.
Well, as mentioned in IRC, this should do:
NSString *s = @"blah";
unsigned char *cs = ;
for (cs = [s UTF8String]; *cs != '\0'; cs++)
printf("0x%02X", *cs);
Octal should be "%02o".
This might help with understanding what bytes you can expect in the
output:
http://www1.tip.nl/~t876506/utf8tbl.html
regards,
Helge
--
http://docs.opengroupware.org/Members/helge
OpenGroupware.org