• 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 String Representations at Runtime
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Converting String Representations at Runtime


  • Subject: Re: Converting String Representations at Runtime
  • From: Michael Ash <email@hidden>
  • Date: Sun, 12 Apr 2009 22:21:50 -0400

On Sun, Apr 12, 2009 at 6:01 PM, John Joyce
<email@hidden> wrote:
> Is there an easy way to take input (user or file based) at runtime and
> convert unicode strings such as \u8D64 (UTF8 character) or a whole series of
> these to the human-readable characters they represent?
> I imagine I should be using NSScanner, but is there not some simple function
> or method to lookup and return the character as it should be represented?
> Happy to RTFM, just need a pointer to the docs I should be looking at.

Note that those are just unicode code points, not UTF-8 "characters",
whatever that would be. There is nothing built-in that I know of to
convert these.

You can search the string using one of the built-in methods, and then
read the number with NSScanner's -scanHexInt:. If you know that your
code points will always be no more than 4 digits (16 bits), which I
think would have to be the case because otherwise you wouldn't know
where to stop scanning the number, then you can make a string out of
it easily using the %C format specifier, like so:

unsigned value;
if([scanner scanHexInt:&value]) {
    NSString *str = [NSString stringWithFormat:@"%C", value];
    ... put str back into the original string ...
}
else // couldn't parse the value

Mike
_______________________________________________

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 String Representations at Runtime
      • From: Ken Thomases <email@hidden>
References: 
 >Converting String Representations at Runtime (From: John Joyce <email@hidden>)

  • Prev by Date: Re: stopping an application
  • Next by Date: Re: stopping an application
  • Previous by thread: Converting String Representations at Runtime
  • Next by thread: Re: Converting String Representations at Runtime
  • Index(es):
    • Date
    • Thread