Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

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

Posted on 2006-04-05
4
Medium Priority
?
1,806 Views
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.
0
Comment
Question by:aeijohn
  • 2
4 Comments
 
LVL 16

Expert Comment

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

Author Comment

by:aeijohn
ID: 16385440
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?
0
 
LVL 16

Expert Comment

by:George Tokas
ID: 16385800
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.
0
 
LVL 9

Accepted Solution

by:
Cayce earned 750 total points
ID: 16392580
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;

0

Featured Post

[Webinar] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
The viewer will learn how to use NetBeans IDE 8.0 for Windows to connect to a MySQL database. Open Services Panel: Create a new connection using New Connection Wizard: Create a test database called eetutorial: Create a new test tabel called ee…
The viewer will learn how to synchronize PHP projects with a remote server in NetBeans IDE 8.0 for Windows.
Suggested Courses

564 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