Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: Convertging a char * string with Swedish character to UnicodeString 64-bit



Permlink Replies: 1 - Last Post: Oct 13, 2015 2:56 PM Last Post By: Remy Lebeau (Te...
sverker johansson

Posts: 12
Registered: 9/28/08
Convertging a char * string with Swedish character to UnicodeString 64-bit
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 13, 2015 12:17 PM
Converting a char * string with Swedish character to UnicodeString get no good result for 64-bit but OK för 32-bit application
Example
char *pC = “Text with Swedish characters for instants åöä”;
UnicodeString ucS = pC; // gives no correct chars for the Swedish chars in the 64-bits system

CX10 , Windows 10

What to do ?
/Sverker Johansson
Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: Convertging a char * string with Swedish character to UnicodeString64-bit
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 13, 2015 2:56 PM   in response to: sverker johansson in response to: sverker johansson
sverker wrote:

Converting a char * string with Swedish character to UnicodeString
get no good result for 64-bit but OK för 32-bit application

Example

char *pC = “Text with Swedish characters for instants åöä”;

UnicodeString ucS = pC; // gives no correct chars for the Swedish chars
in the 64-bits system

There is no difference in how characters are converted between 32bit and
64bit. What is more important is that you are converting a string literal
from Ansi to Unicode, which uses the OS default codepage for the conversion,
and your literal is subject to the encoding of the source file itself. So
if the source file is using a different encoding than the OS (or if the compiler
is interpretting the source file as a different encoding - remember that
32bit and 64bit use different compilers), the conversion will not work correctly.

You need to write this kind of code in a manner that ensures consistent and
predictable encodings and conversions. For example:

wchar_t *pC = L"Text with Swedish characters for instants åöä";
 
UnicodeString ucS = pC;


Or:

// this works in the clang 32bit and 64bit compilers, but not in the classic 
32bit compiler
char *pC = u8"Text with Swedish characters for instants åöä";
 
UnicodeString ucS = UTF8String(pC);


Or:

// this works in the clang 32bit and 64bit compilers, but not in the classic 
32bit compiler
char16_t *pC = u"Text with Swedish characters for instants åöä";
 
UnicodeString ucS = pC;


--
Remy Lebeau (TeamB)
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02