setlocale(LC_ALL, en_US.UTF-8) failing on ipad but working fine on simulator

While converting a char* to wchar*, i am setting the locale as en_US.UTF-8. The setlocale function returns NULL on iPad due to which incorrect string is displayed. I also tried "en_US" locale but the converted wchar string is still incorrect and is same as it was in the case of locale failure. I don't know if i am missing something. Please help.

iPad, iOS 5.0.1

Posted on Dec 15, 2011 5:42 AM

Reply
4 replies

Dec 16, 2011 2:45 PM in response to luckymascot

I know the reason for the wchar. My question was more rhetorical to make you think.


You have Cocoa on the iPad. All of your user-generated string input is already in NSStrings that fully support Unicode. There are NSString methods to convert to UTF8 C strings if you need them. If you are getting data from some internet source, it will likely already be in UTF8.


In short, there is no reason to use wchar unless you just really want to do 3 times the work and you enjoy punishing yourself.

Oct 4, 2016 11:29 AM in response to luckymascot

Dear luckymascot,


it's been a while - have you ever figured out how to solve this ?


I am trying to utilise strftime() to achieve a portable (Android/iOS) implementation of certain calendar functions.

For localisation, I use setlocale(LC_TIME, "fr_FR") (e.g.) - which works beautifully with the iOS simulator, but fails on any iOS device. - On devices, setlocale() always returns NULL ...

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

setlocale(LC_ALL, en_US.UTF-8) failing on ipad but working fine on simulator

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.