Re: Converting wchar_t string to NSString
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.