Re: converting unicode text representation to unichar
Re: converting unicode text representation to unichar
- Subject: Re: converting unicode text representation to unichar
- From: Alastair Houghton <email@hidden>
- Date: Tue, 11 Aug 2009 16:12:59 +0100
On 11 Aug 2009, at 15:40, Daniel Child wrote:
Unihan.txt provides text files showing characters in the format U
+XXXX.
If I scan these in, naturally I can obtain the NSString
representation XXXX.
But I need to convert this text to genuine unichars OR NSStrings
(the actual characters represented).
Two questions:
1. I didn't see any relevant conversion methods under NSString or
NSNumber. Are there Cocoa functions to perform this easily?
Use NSScanner's -scanHexInt (or similar) to scan the hexadecimal part,
then stick that in a unichar and either use -stringWithFormat's %C
format code, or NSString's -initWithCharacters:length:/
+stringWithCharacters:length: methods.
Or you can just scan the hex part yourself manually; it isn't hard.
You could even turn it into UTF-8 and use strtoul() if you were
feeling mildly masochistic.
2. I am assuming I have to convert to the format '0xXXXX', but is it
also possible to work with U+XXXX directly in cocoa? I got error
messages for all of the following formats:
unichar uch = 0x0041;
NSString *str = [NSString stringWithCharacters:&uch length:1];
NSLog (@"str is \"%@\".", str);
/* Output:
str is "A" */
Kind regards,
Alastair.
--
http://alastairs-place.net
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please 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