• 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: converting unicode text representation to unichar
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


  • Follow-Ups:
    • Re: converting unicode text representation to unichar
      • From: Daniel Child <email@hidden>
References: 
 >converting unicode text representation to unichar (From: Daniel Child <email@hidden>)

  • Prev by Date: Re: [iPhone] seeking advise on complex view design
  • Next by Date: Re: converting unicode text representation to unichar
  • Previous by thread: converting unicode text representation to unichar
  • Next by thread: Re: converting unicode text representation to unichar
  • Index(es):
    • Date
    • Thread