How to convert a Unicode text file into Ascii?
-
I want to convert a text file, which is encoded in Unicode, into a Ascii one. The text is a mixture of Chinese characters and English. How can I do that?
-
I want to convert a text file, which is encoded in Unicode, into a Ascii one. The text is a mixture of Chinese characters and English. How can I do that?
Use the API function WideCharToMultiByte() which is well documented on MSDN. It also depends if you want to convert to ascii (and hence lose all Chinese characters) or to an ansi code page that still allows the chinese characters to be retrieved (a multi-byte character set). If you want to go to ascii, you can use 1252 as the target codepage. If you are running this on a Chinese system (i.e. Chinese Windows, or English Windows with Chinese regional settings), then you can pass in CP_ACP as the target code page, and it will convert it to the current system codepage, which should include the chinese characters. If this is not a chinese system, then you will need to pass in the chinese code page number instead (which i can't remember of the top of my head). Dave