• 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 wchar_t string to NSString
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Converting wchar_t string to NSString


  • Subject: Re: Converting wchar_t string to NSString
  • From: Andrew Thompson <email@hidden>
  • Date: Sun, 8 Feb 2004 08:19:52 -0500

On Feb 8, 2004, at 12:32 AM, Glen Low wrote:

As a followup to this, does anybody know how to convert a string in 32-bit unicode into NSString? Right now I took the easy way out. wxWindows can convert from wchar_t (used internally in its "unicode" mode) to/from UTF-8 and NSString can do the same.

What's the best way to go straight from a wchar_t string to an NSString? Keep in mind it would be helpful if this worked on OS < 10.3 because we may decide to implement our on wide-character C library functions so that wxCocoa can be compiled and run in unicode mode on any version of OS X.

This is an educated guess, and I'm assuming your wchar_t string is already in Unicode (as opposed to some other 2-byte encoding).

initWithCharacters: length: could be used with 1st param cast from your wchar_t string. length = wcslen * 2.

initWithBytes: length: encoding: could be used with encoding = NSUnicodeStringEncoding. length = wcslen * 2.

CFStringCreateWithBytes could be used with encoding = CFStringEncodingUnicode. (CFStringRef is toll-free bridged with NSString).

Indeed, the first question I'd attempt to answer is "what encoding is my wchar_t" string in?

Scroll down to point 13 on this page for a good explanation of the difference between a character set & a character encoding:

http://www.cafeconleche.org/books/effectivexml/chapters/00.html

Essentially your wchar_t is in the Unicode Character Set, but which Encoding? If its truly a 4 byte encoding, the most likely candidates are UTF-32 or UCS-4. Once you know the answer to this, you should be able to use one of the functions Glen mentions.

AndyT (lordpixel - the cat who walks through walls)
A little bigger on the inside

(see you later space cowboy ...)
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

  • Follow-Ups:
    • Re: Converting wchar_t string to NSString
      • From: David Elliott <email@hidden>
References: 
 >Re: Converting Japanese C- string to NSString (From: Darrin Cardani <email@hidden>)
 >Re: Converting Japanese C- string to NSString (From: John Stiles <email@hidden>)
 >Converting wchar_t string to NSString (From: David Elliott <email@hidden>)
 >Re: Converting wchar_t string to NSString (From: Glen Low <email@hidden>)

  • Prev by Date: applicationShouldTerminateAfterLastWindowClosed
  • Next by Date: Re: Changing a filename while the FSRef is in use
  • Previous by thread: Re: Converting wchar_t string to NSString
  • Next by thread: Re: Converting wchar_t string to NSString
  • Index(es):
    • Date
    • Thread