{文字列}{wxWidgets}(2)

{wxWidgets における文字列 K#F85E/6C8A}

wxWidgets における文字列

wxString が基本の文字列型である。

Unicode ビルドの場合,文字・文字列定数には wxT マクロを使う必要がある。

UnicodeビルドではUnicodeに変換された文字列を返す。

非 Unicode ビルドの場合、文字列の内容を変更せずに返す。

相互変換

C 文字列から wxString

一番簡単なのは

wxString str(wxT("some text"));

Unicodeビルドの場合、

wxString str = wxString::FromAscii("some text");
または
wxString str = wxString::From8BitData("some text");
が使える。

より一般的には、下記の方法がASCII、Unicodeともに問題なく動く。

wxString str("some text", wxConvUTF8);

std::string から wxString

std::string stdstr = "some text";
wxString str(stdstr.c_str(), wxConvUTF8);

wxString からC 文字列

wxString str(wxT("some text"));
str.mb_str(wxConvUTF8);