Output wxString as UTF8
Milan Babuskov
milanb at panonnet.net
Fri Sep 29 09:14:34 PDT 2006
Vadim Zeitlin wrote:
> MB> I have a string (which is in current system encoding) and I wish to
> MB> output it to the textual file in UTF8 format. What would be the
> MB> appropriate way to convert wxString from current system encoding to UTF8?
>
> I assume you're using ANSI build of wx
Both Unicode and ANSI.
> In this case, you need to first
> convert the string to Unicode and then encode it in UTF-8:
>
> wxConvUTF8.cWC2MB(wxConvCurrent->cMB2WC(s));
>
> You can also use s.wc_str(*wxConvCurrent) instead of the inner conversion.
Ok, I guess for Unicode build I don't need the first step?
Is the following the right way to do it:
wxString current2utf8(const wxString& src)
{
#if wxUSE_UNICODE
return wxConvUTF8.cWC2MB(src);
#else
return wxConvUTF8.cWC2MB(wxConvCurrent->cMB2WC(src));
#endif
}
> Regards,
> VZ
Thanks,
--
Milan Babuskov
http://www.flamerobin.org
More information about the wx-users
mailing list