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

Posted on 2006-04-05
Last Modified: 2013-11-17
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.
Question by:aeijohn
    LVL 16

    Expert Comment

    by:George Tokas
    >>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.


    Author Comment

    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?
    LVL 16

    Expert Comment

    by:George Tokas
    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...

    LVL 9

    Accepted Solution

    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;


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    In our object-oriented world the class is a minimal unit, a brick for constructing our applications. It is an abstraction and we know well how to use it. In well-designed software we are not usually interested in knowing how objects look in memory. …
    Programmer's Notepad is, one of the best free text editing tools available, simply because the developers appear to have second-guessed every weird problem or issue a programmer is likely to run into. One of these problems is selecting and deleti…
    This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
    The viewer will learn how to use and create keystrokes in Netbeans IDE 8.0 for Windows.

    761 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    11 Experts available now in Live!

    Get 1:1 Help Now