Re: cstring to cbytearray conversion



FWIW, I agree with David, for anything "internet", UTF-8 is a better
choice.

It's not hard: save/manipulate all your stuff in Unicode encoding
supported by the system (here: UTF-16LE). Convert to UTF-8 for that
final send over the wire. So just use CString with UNICODE (that is,
use CStringW), and, before you put it on the wire, use
WideCharToMultiByte(CP_UTF8, ...).

(
To do that easily, you'll probably decide that you need helpers like
these:

// Use WideCharToMultiByte(CP_UTF8, ...) here.
CStringA UTF8(const CStringW& src);
CStringA UTF8(LPCWSTR src);
CStringA UTF8(LPCWSTR src, int length);
)

Goran.
.



Relevant Pages

  • Re: cstring to cbytearray conversion
    ... If your HTML is saved as UTF-8, ... into CStringA, not touch it at all, and send it like that. ... This is because constructor you're ... or doing it in UTF-16. ...
    (microsoft.public.vc.mfc)
  • Re: CString and UTF-8
    ... UTF-8 encodes extended character sets using only 8-bit bytes. ... OK, CStringA could be used as a simple "dumb" container for bytes, but ...
    (microsoft.public.vc.mfc)
  • Re: Want Input boxes to accept unicode strings on Standard Window
    ... One nice thing about UTF-8 is that if you do most of your files in English ... of having smaller files for English or other languages where more than one ... The bad thing is that Windows doesn't support UTF-8 ... the contents and store them using CStringA, ...
    (microsoft.public.vc.mfc)
  • Re: DB2 UTF-8 ODBC double conversion
    ... have Unicode strings, so CStrings are UTF-8 strings when dealing with pretty much everything except GUI. ... (Note that you may want to use CStringA explicitly or std::string, so even if you switch your app to Unicode, your strings will continue storing UTF-8 data.) ...
    (microsoft.public.vc.mfc)