• 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: Glen Low <email@hidden>
  • Date: Sun, 8 Feb 2004 13:32:26 +0800

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).







Cheers, Glen Low


---
pixelglow software | simply brilliant stuff
www.pixelglow.com
_______________________________________________
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: Andrew Thompson <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>)

  • Prev by Date: Re: Drawing onto NSImageView subclass (Newbie)
  • Next by Date: Re: Sending and receiving files to remote server through cocoa
  • Previous by thread: Converting wchar_t string to NSString
  • Next by thread: Re: Converting wchar_t string to NSString
  • Index(es):
    • Date
    • Thread