Link to home
Start Free TrialLog in
Avatar of aeijohn
aeijohn

asked on

What is best way to convert an hex unicode to AnsiString?

Using Borland C++ Builder, what is best way to convert an hex unicode to AnsiString? Ideally, for me, the input would be hex code is in AnsiString with format of "u\ABCD"; output is AnsiString.
Avatar of George Tokas
George Tokas
Flag of Greece image

>>the input would be hex code is in AnsiString with format of "u\ABCD";
Didn't get it... What does that mean??
If you have the unicode buffer just assign it to an AnsiString as follows:
char *Buffer;
//what you want put it in...
AnsiString S = Buffer;
//The contents of the buffer (allways in Hex) will be translated to AnsiString.

gtokas.
Avatar of aeijohn
aeijohn

ASKER

u\ABCD should of been \uabcd, but doesnt matter as I stripped out "abcd" and add "0x" to become "0xabcd".

Your coding only gave error - cannot convert int to char*.

I tried thisL

AnsiString st,su,sx;
.
.
su="00a9" //value varies when called
TCHAR sx[10];
sx[0]=NULL;
su="0x"+su;
wsprintf(sx,"%c",su.ToInt());
st+=sx;

which seems to works for 0x00a9, but gives garbage for 0x5b89 (represents Chinese character) when viewed in TList or TMemo (Font and Font Name = MS Sans Serif.)

Any ideas why 0x5b89 is not showned correctly?
Nice aproach...:-)
A bit MFC... Let me show you the BCB way:
AnsiString st,su,sx;
.
.
su="00a9" //value varies when called
>>TCHAR sx[10];
sx.SetLength[10];

>>sx[0]=NULL;
You can use and this way...

>>su="0x"+su;
NICE!
>>wsprintf(sx,"%c",su.ToInt());
Equal to sx = su;

Now:
If I'm correct unicode is wchar thus a word...
0x00a9 its 0x00 unicode page and 0xa9 the displayed character.... For Chinese the unicode page has to be 0x5b and 0x89 the displayed character.
Check out for "unicode" at online help and see if there is something you can use... I found many handy functions there...
Also to display them ok it will be better to use a RichEdit component...

gtokas.
ASKER CERTIFIED SOLUTION
Avatar of Cayce
Cayce
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial