OVERVIEW
Strings are used in every application so the wxString class is something which will be used very often. Given below is code which shows the various basic string functions available.
SAMPLE CODE
strings.cpp
#include <wx/wxprec.h>
#ifndef WX_PRECOMP
#include <wx/wx.h>
#endif
#include <wx/string.h>
int main(int argc, char **argv) {
wxInitialize();
wxString str1 = wxT("First ");
wxString str2 = wxT("Second ");
wxString str3 = wxT("Third ");
wxPuts(wxT("Concatenating:\n"));
wxPuts(str1 + str2 + str3);
wxPuts(wxT("\nAppending:\n"));
wxPuts(str1.Append(str3));
wxPuts(wxT("\nLength and Format:\n"));
wxString strLen = wxString::Format(wxT("Length is %zu"), str1.Length());
wxPuts(strLen);
wxPuts(wxT("\nCase:\n"));
wxPuts(str1.Upper() + wxT(" ") + str1.Lower() + wxT(" ") + str1.Capitalize());
wxPuts(wxT("\nExtraction:\n"));
wxPuts(str1.Left(3) + wxT(" " ) + str1.Right(2) + wxT(" ") + str1.Mid(2,3));
wxPuts(wxT("\nSearch:\n"));
if (str1.Contains("irst"))
wxPuts(str1 + wxT(" contains irst"));
if (str1.Find("dssd") == wxNOT_FOUND)
wxPuts(str1 + wxT(" could not find dssd"));
wxUninitialize();
}
The output is given below:
Concatenating: First Second Third Appending: First Third Length and Format: Length is 12 Case: FIRST THIRD first third First third Extraction: Fir d rst Search: First Third contains irst First Third could not find dssd
Leave a Reply