Copying the contents of a wxString
chris elliott
biol75 at york.ac.uk
Fri Sep 8 05:52:18 PDT 2006
You may find some of the docs helpful; for example
http://biolpc22.york.ac.uk/wx/docs/html/wx/wx_unicode.html#unicode
says::
To get an ANSI string from a wxString, you may use the mb_str() function
which always returns an ANSI string (independently of the mode - while
the usual c_str() returns a pointer to the internal representation which
is either ASCII or Unicode). More rarely used, but still useful, is
wc_str() function which always returns the Unicode string.
chris
Michiel.Salters at tomtom.com wrote:
> Peter Gordon wrote:
>> I need to copy the contents of a wxString to a separate, non-wxString
>> buffer.
>
> Do you need to add a \0? wxString is a C++ class and doesn't need one,
> but C "strings" do need them.
>
>> The pointer is wxString::c_str(), but what is the length that needs to
>> be copied assuming that I am using Unicode? Do I need to take
>> wxString::Len(),
>> wxString::Len() * sizeof(w_char),
>> wxString::Len() * sizeof(w_char) + 1,
>> or what?
>
> The first two could be correct. ::Len gives you the number of wchar_t's
> (in the unicode case). ::Len() * sizeof(w_char) gives you the number of
> bytes. However, it's more portable to use * sizeof(wxString[0]).
>
> The third looks like you copy to a C-string buffer, except that you
> need to
> add sizeof(wchar_t), not 1 as a wchar_t[] string is terminated with
> L'\0'.
> You could also write (wxString::Len() +1) * sizeof(wchar_t).
>
> HTH,
> Michiel Salters
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: wx-users-unsubscribe at lists.wxwidgets.org
> For additional commands, e-mail: wx-users-help at lists.wxwidgets.org
>
More information about the wx-users
mailing list