Switching TCHAR to UTF-8
-
Hey all... I am trying to write out a Japanese text string in a data file which was originally specified for ANSI text and used across several applications. Basically what was suggested was that I use UTF-8 to write out the text strings and read them back in. One of the constraints is that the current applications that read English only should still be able to read English data if this application writes it. However the old applications can punt on the Japanese until they are also updated. I can figure out how to write from MBCS to UTF-8:
#ifndef UNICODE MultiByteToWideChar(CP_UTF8, dwFlags, lpMBCSStr, cbMBCS, lpWCStr, cchWCStr) #endif
However we normally build in UNICODE using TCHAR, and it is normally UTF-16. However I just want to convert this one string from UTF-16 to UTF-8. Anyone ever done this? You can also just call me insane and stupid as long as you can suggest a better approach. I don't mind being insulted if I can learn something. :-D Brian If you start a fire for a man, he will be warm for a day. If you start that same man on fire, he will be warm for the rest of his life. -
Hey all... I am trying to write out a Japanese text string in a data file which was originally specified for ANSI text and used across several applications. Basically what was suggested was that I use UTF-8 to write out the text strings and read them back in. One of the constraints is that the current applications that read English only should still be able to read English data if this application writes it. However the old applications can punt on the Japanese until they are also updated. I can figure out how to write from MBCS to UTF-8:
#ifndef UNICODE MultiByteToWideChar(CP_UTF8, dwFlags, lpMBCSStr, cbMBCS, lpWCStr, cchWCStr) #endif
However we normally build in UNICODE using TCHAR, and it is normally UTF-16. However I just want to convert this one string from UTF-16 to UTF-8. Anyone ever done this? You can also just call me insane and stupid as long as you can suggest a better approach. I don't mind being insulted if I can learn something. :-D Brian If you start a fire for a man, he will be warm for a day. If you start that same man on fire, he will be warm for the rest of his life.MultiByteToWideChar()
is the right way to convert from UTF-16 to UTF-8. It doesn't matter what yourUNICODE
setting is because that API's input is always UTF-16 and the output is always a multi-byte encoding. --Mike-- Personal stuff:: Ericahist | Homepage Shareware stuff:: 1ClickPicGrabber | RightClick-Encrypt CP stuff:: CP SearchBar v2.0.2 | C++ Forum FAQ ----