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.
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

George TokasCommented:
>>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.

aeijohnAuthor Commented:
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];

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?
George TokasCommented:
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];

You can use and this way...

Equal to sx = su;

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

having your wchar_t* array of "hex" unicode characters should be easily transformed into a WideString, which can be changed to and AnsiString.

            wchar_t stringA[] = { 0x0033, 0x0034, 0x0030, 0x0000 };
            WideString stringB = stringA;
            AnsiString stringC = stringB;


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Editors IDEs

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.