Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Convert 1 bye to 2 bytes

Status
Not open for further replies.

Lorey

Programmer
Feb 16, 2003
88
SG
Hi!

I have an application which is not yet unicode supported, and have no plans of doing so as of the momment.

But I have a module in it that needs to convert all the users input (in CEdit control) to 2 bytes. I need to make all ascii text to be properly formatted in 2 bytes (i.e. h e l l o). the chinese text appears ok. coz one char already consider as 2 bytes.

The bigger problem is the user can also input mix english and chinese in the edit control.

i stored the value in Cstring and std::string.

Do you know a way where when i get the values from the control, its already formatted properly in 2 bytes. or is there anyway? The most important thing is to get all the users iinput in 2 bytes.
 
hi,
convert 1-byte to 2-bytes is machining speaking very easy:
you put your byte in the low part of the 2-bytes-word and
set to zero the high part of it.

Your example ("h e l l o "), is not perfect:
it is written in 10 chars, one byte large each,
while you have to write in 5 chars, 2 bytes large each.

See in MSDN (or help of your Visual c++) the use of
TCHAR macro (or _TCHAR): using this instead the word "char"
would give you the ability to don't rewrite code when you
pass at unicode:

use

_TCHAR buff[_MAX_PATH];

instead

char buff[_MAX_PATH];


bye
Vittorio
 
MultiByteToWideChar might be what you need.

------------------
When you do it, do it right.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top