Converting a C string to wxString
Vadim Zeitlin
vadim at wxwidgets.org
Fri Jan 4 06:19:32 PST 2008
On Fri, 4 Jan 2008 12:29:06 -0000 Marc de Kamps <dekamps at comp.leeds.ac.uk> wrote:
MdK> I'm a novel user of wxGTK. I have to port some legacy code to the latest
MdK> version that we use here 2.8 on a FEDORA linux platform compiled with
MdK> Unicode support. The old code used version 2.4.2.
MdK>
MdK> One of the main differences appear to be that there is no more implicit
MdK> conversion from (ANSI) C strings to wxString
This is true in Unicode build but not in ANSI one. You can still build
even 2.8 in ANSI mode and while this does mean that you won't be able to
handle non-ASCII characters easily, if it's not a problem for you, it's
probably much simpler to just do this than to update your legacy code.
MdK> What I do not understand is how an ANSI C string that is not a literal
MdK> should be converted into a wxString, for example,
MdK> I've been passed an STL string str_example and apparently I need a converter
MdK> object to convert into a wxString object:
MdK>
MdK> wxString wx_example(str_example.c_str(),*wxConvCurrent);
MdK>
MdK> How do I do determine which converter I need?
This is determined solely by the encoding of the original string. If it's
(7 bit) ASCII, you can just use wxString::FromAscii(). If it's an 8 bit
string in current locale, then wxConvCurrent is what you need. If it's in
UTF-8, then you need wxConvUTF8.
Regards,
VZ
--
TT-Solutions: wxWidgets consultancy and technical support
http://www.tt-solutions.com/
More information about the wx-users
mailing list