Version: 3.3.1
Loading...
Searching...
No Matches
string.h File Reference

Classes

class  wxString
 String class for passing textual data to or receiving it from wxWidgets. More...
class  wxStringBufferLength
 This helper class allows you to conveniently access the wxString internal buffer as a writable pointer and requires explicitly specifying the actual length. More...
class  wxStringBuffer
 This helper class allows you to conveniently access the wxString internal buffer as a writable pointer and automatically determines its length. More...

Typedefs

Standard types

Types used with wxString.

typedef wxUniChar value_type
typedef wxUniChar char_type
typedef wxUniCharRef reference
typedef wxCharpointer
typedef const wxCharconst_pointer
typedef size_t size_type
typedef wxUniChar const_reference

Functions

size_t Length () const
 Returns the length of the string (same as Len).
bool IsEmpty () const
 Returns @true if the string is empty.
bool IsNull () const
 Returns @true if the string is empty (same as wxString::IsEmpty).
bool operator! () const
 Empty string is @false, so !string will only return @true if the string is empty.
**const wxCStrData GetData () const
 @member_group_name{string_ch_access, Character access}
wxUniCharRef GetWritableChar (size_t n)
 Returns a reference to the character at position n.
void SetChar (size_t n, wxUniChar ch)
 Sets the character at position n.
wxUniChar Last () const
 Returns the last character.
wxUniChar operator[] (size_t i) const
 Returns the i-th character of the string.
**wxWritableCharBuffer char_str (const wxMBConv &conv=wxConvLibc) const
 @member_group_name{string_convs, Conversions}
template<typename T>
wxCharTypeBuffer< T > tchar_str (size_t *len=nullptr) const
 Returns buffer of the specified type containing the string data.
const TYPE fn_str () const
 Returns a string representation suitable for passing to OS' functions for file handling.
const wxCharBuffer mb_str (const wxMBConv &conv=wxConvLibc) const
 Returns the multibyte (C string) representation of the string using conv's wxMBConv::cWC2MB method and returns wxCharBuffer.
const wxScopedCharBuffer utf8_str () const
 Converts the strings contents to UTF-8 and returns it either as a temporary wxCharBuffer object or as a pointer to the internal string contents in UTF-8 build.
const std::string utf8_string () const
 Return the string as an std::string using UTF-8 encoding.
const wxWX2WCbuf wc_str () const
 Returns the strings contents as a wide character string.
std::wstring wc_string () const
 Returns the strings contents as a wide character string.
wxWritableWCharBuffer wchar_str () const
 Returns an object with string data that is implicitly convertible to char* pointer.
const wxStringCharTypewx_str () const
 Explicit conversion to C string in the internal representation (either wchar_t* or UTF-8-encoded char*, depending on the build).
const wxScopedCharBuffer To8BitData () const
 Converts the string to an 8-bit string in ISO-8859-1 encoding in the form of a wxCharBuffer.
const wxCharBuffer ToAscii (char replaceWith='_') const
 Converts the string to an ASCII, 7-bit string.
std::string ToStdString (const wxMBConv &conv=wxConvLibc) const
 Return the string as a std::string using conv's wxMBConv::cWC2MB method.
std::wstring ToStdWstring () const
 Return the string as a std::wstring.
const wxScopedCharBuffer ToUTF8 () const
 Same as utf8_str().
**wxStringAppend (const wchar_t *pwz)
 @member_group_name{string_concat, Concatenation}
wxStringAppend (const char *psz, size_t nLen)
 Appends the string literal psz with max length nLen.
wxStringAppend (const wchar_t *pwz, size_t nLen)
 Appends the wide string literal psz with max length nLen.
wxStringAppend (const wxString &s)
 Appends the string s.
wxStringAppend (wxUniChar ch, size_t count=1u)
 Appends the character ch count times.
wxStringPrepend (const wxString &str)
 Prepends str to this string, returning a reference to this string.
wxString operator+ (const wxString &x, const wxString &y)
 Concatenation: returns a new string equal to the concatenation of the operands.
wxString operator+ (const wxString &x, wxUniChar y)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
wxStringoperator<< (const wxString &s)
wxStringoperator<< (const char *psz)
wxStringoperator<< (const wchar_t *pwz)
wxStringoperator<< (const wxCStrData &psz)
wxStringoperator<< (char ch)
wxStringoperator<< (unsigned char ch)
wxStringoperator<< (wchar_t ch)
wxStringoperator<< (const wxCharBuffer &s)
wxStringoperator<< (const wxWCharBuffer &s)
wxStringoperator<< (wxUniChar ch)
wxStringoperator<< (wxUniCharRef ch)
wxStringoperator<< (unsigned int ui)
wxStringoperator<< (long l)
wxStringoperator<< (unsigned long ul)
wxStringoperator<< (wxLongLong_t ll)
wxStringoperator<< (wxULongLong_t ul)
wxStringoperator<< (float f)
wxStringoperator<< (double d)
void operator+= (const wxString &str)
 Concatenation in place: the argument is appended to the string.
void operator+= (wxUniChar c)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
**int CmpNoCase (const wxString &s) const
 @member_group_name{string_cmp, Comparison}
bool IsSameAs (const wxString &s, bool caseSensitive=true) const
 Test whether the string is equal to another string s.
bool IsSameAs (wxUniChar ch, bool caseSensitive=true) const
 Test whether the string is equal to the single character ch.
*friend bool operator!= (const wxString &s1, const wxString &s2)
bool operator< (const wxString &s1, const wxString &s2)
bool operator> (const wxString &s1, const wxString &s2)
bool operator<= (const wxString &s1, const wxString &s2)
bool operator>= (const wxString &s1, const wxString &s2)
bool operator== (const wxString &s1, const wxCStrData &s2)
bool operator== (const wxCStrData &s1, const wxString &s2)
bool operator!= (const wxString &s1, const wxCStrData &s2)
bool operator!= (const wxCStrData &s1, const wxString &s2)
bool operator== (const wxString &s1, const wxWCharBuffer &s2)
bool operator== (const wxWCharBuffer &s1, const wxString &s2)
bool operator!= (const wxString &s1, const wxWCharBuffer &s2)
bool operator!= (const wxWCharBuffer &s1, const wxString &s2)
bool operator== (const wxString &s1, const wxCharBuffer &s2)
bool operator== (const wxCharBuffer &s1, const wxString &s2)
bool operator!= (const wxString &s1, const wxCharBuffer &s2)
bool operator!= (const wxCharBuffer &s1, const wxString &s2)
**friend bool operator== (const wxUniCharRef &c, const wxString &s)
bool operator== (char c, const wxString &s)
bool operator== (wchar_t c, const wxString &s)
bool operator== (int c, const wxString &s)
bool operator== (const wxString &s, const wxUniChar &c)
bool operator== (const wxString &s, const wxUniCharRef &c)
bool operator== (const wxString &s, char c)
bool operator== (const wxString &s, wchar_t c)
bool operator!= (const wxUniChar &c, const wxString &s)
bool operator!= (const wxUniCharRef &c, const wxString &s)
bool operator!= (char c, const wxString &s)
bool operator!= (wchar_t c, const wxString &s)
bool operator!= (int c, const wxString &s)
bool operator!= (const wxString &s, const wxUniChar &c)
bool operator!= (const wxString &s, const wxUniCharRef &c)
bool operator!= (const wxString &s, char c)
bool operator!= (const wxString &s, wchar_t c)
*bool Matches (const wxString &mask) const
 Returns @true if the string contents matches a mask containing '*' and '?
bool StartsWith (const wxString &prefix, wxString *rest=nullptr) const
 This function can be used to test if the string starts with the specified prefix.
bool EndsWith (const wxString &suffix, wxString *rest=nullptr) const
 This function can be used to test if the string ends with the specified suffix.
**wxString SubString (size_t from, size_t to) const
 @member_group_name{string_substring, Substring extraction}
wxString operator() (size_t start, size_t len) const
 Same as Mid() (substring extraction).
wxString Left (size_t count) const
 Returns the first count characters of the string.
wxString Right (size_t count) const
 Returns the last count characters.
wxString AfterFirst (wxUniChar ch) const
 Gets all the characters after the first occurrence of ch.
wxString AfterLast (wxUniChar ch) const
 Gets all the characters after the last occurrence of ch.
wxString BeforeFirst (wxUniChar ch, wxString *rest=nullptr) const
 Gets all characters before the first occurrence of ch.
wxString BeforeLast (wxUniChar ch, wxString *rest=nullptr) const
 Gets all characters before the last occurrence of ch.
**wxString Lower () const
 @member_group_name{string_caseconv, Case conversion}
void LowerCase ()
 Same as MakeLower.
wxStringMakeCapitalized ()
 Converts the first characters of the string to the upper case and all the subsequent ones to the lower case and returns the result.
wxStringMakeLower ()
 Converts all characters to lower case and returns the reference to the modified string.
wxStringMakeUpper ()
 Converts all characters to upper case and returns the reference to the modified string.
wxString Upper () const
 Returns this string converted to upper case.
void UpperCase ()
 The same as MakeUpper().
**int Find (const wxString &sub) const
 @member_group_name{string_search, Searching and replacing}
int First (wxUniChar ch) const
 Same as Find().
int First (const wxString &str) const
 Same as Find().
size_t Replace (const wxString &strOld, const wxString &strNew, bool replaceAll=true)
 Replace first (or all) occurrences of substring with another one.
**bool ToCDouble (double *val) const
 @member_group_name{string_numconv, Conversion to numbers}
bool ToInt (int *val, int base=10) const
 Works like ToLong() but for signed integers.
bool ToUInt (unsigned int *val, int base=10) const
 Works like ToULong() but for unsigned integers.
bool ToLong (long *val, int base=10) const
 Attempts to convert the string to a signed integer in base base.
bool ToCLong (long *val, int base=10) const
 Variant of ToLong() always working in "C" locale.
bool ToLongLong (wxLongLong_t *val, int base=10) const
 This is exactly the same as ToLong() but works with 64 bit integer numbers.
bool ToULong (unsigned long *val, int base=10) const
 Attempts to convert the string to an unsigned integer in base base.
bool ToCULong (unsigned long *val, int base=10) const
 Variant of ToULong() always working in "C" locale.
bool ToULongLong (wxULongLong_t *val, int base=10) const
 This is exactly the same as ToULong() but works with 64 bit integer numbers.
**int PrintfV (const wxString &pszFormat, va_list argPtr)
 @member_group_name{string_fmt, Formatting and printing}
**bool Shrink ()
 @member_group_name{string_mem, Memory management}
wxString Clone () const
 Returns a copy of the string.
void Clear ()
 Clears the string's content, setting its length to zero.
**void Empty ()
 @member_group_name{string_misc, Miscellaneous}
int Freq (wxUniChar ch) const
 Returns the number of occurrences of ch in the string.
bool IsAscii () const
 Returns @true if the string contains only ASCII characters.
bool IsNumber () const
 Returns @true if the string is an integer (with possible sign).
bool IsWord () const
 Returns @true if the string is a word.
wxStringPad (size_t count, wxUniChar chPad=' ', bool fromRight=true)
 Adds count copies of chPad to the beginning, or to the end of the string (the default).
wxStringRemove (size_t pos)
 Removes all characters from the string starting at pos.
wxStringRemove (size_t pos, size_t len)
 Removes len characters from the string, starting at pos.
wxStringRemoveLast (size_t n=1)
 Removes the last character.
wxString Strip (stripType s=trailing) const
 Strip characters at the front and/or end.
wxStringTrim (bool fromRight=true)
 Removes white-space (space, tabs, form feed, newline and carriage return) from the left or from the right end of the string (right is default).
wxStringTruncate (size_t len)
 Truncate the string to the given length.
**iterator begin ()
 @member_group_name{string_iter, Iterator interface}
const_iterator cbegin () const
const_iterator end () const
const_iterator cend () const
const_reverse_iterator rbegin () const
const_reverse_iterator crbegin () const
const_reverse_iterator rend () const
const_reverse_iterator crend () const
**wxStringappend (const wxString &str)
 @member_group_name{string_stl, STL interface}
wxStringappend (const char *sz, size_t n)
wxStringappend (const wchar_t *sz, size_t n)
wxStringappend (size_t n, wxUniChar ch)
wxStringappend (const_iterator first, const_iterator last)
wxStringassign (const wxString &str, size_t pos, size_t n)
wxStringassign (const wxString &str)
wxStringassign (const char *sz, size_t n)
wxStringassign (const wchar_t *sz, size_t n)
wxStringassign (size_t n, wxUniChar ch)
wxStringassign (const_iterator first, const_iterator last)
wxUniChar at (size_t n) const
void clear ()
size_type capacity () const
int compare (const wxString &str) const
int compare (size_t nStart, size_t nLen, const wxString &str) const
int compare (size_t nStart, size_t nLen, const wxString &str, size_t nStart2, size_t nLen2) const
int compare (size_t nStart, size_t nLen, const char *sz, size_t nCount=npos) const
int compare (size_t nStart, size_t nLen, const wchar_t *sz, size_t nCount=npos) const
wxCStrData data () const
bool empty () const
wxStringerase (size_type pos=0, size_type n=npos)
iterator erase (iterator first, iterator last)
iterator erase (iterator first)
size_t find (const wxString &str, size_t nStart=0) const
size_t find (const char *sz, size_t nStart=0, size_t n=npos) const
size_t find (const wchar_t *sz, size_t nStart=0, size_t n=npos) const
size_t find (wxUniChar ch, size_t nStart=0) const
size_t find_first_of (const char *sz, size_t nStart=0) const
size_t find_first_of (const wchar_t *sz, size_t nStart=0) const
size_t find_first_of (const char *sz, size_t nStart, size_t n) const
size_t find_first_of (const wchar_t *sz, size_t nStart, size_t n) const
size_t find_first_of (wxUniChar c, size_t nStart=0) const
size_t find_last_of (const wxString &str, size_t nStart=npos) const
size_t find_last_of (const char *sz, size_t nStart=npos) const
size_t find_last_of (const wchar_t *sz, size_t nStart=npos) const
size_t find_last_of (const char *sz, size_t nStart, size_t n) const
size_t find_last_of (const wchar_t *sz, size_t nStart, size_t n) const
size_t find_last_of (wxUniChar c, size_t nStart=npos) const
size_t find_first_not_of (const wxString &str, size_t nStart=0) const
size_t find_first_not_of (const char *sz, size_t nStart=0) const
size_t find_first_not_of (const wchar_t *sz, size_t nStart=0) const
size_t find_first_not_of (const char *sz, size_t nStart, size_t n) const
size_t find_first_not_of (const wchar_t *sz, size_t nStart, size_t n) const
size_t find_first_not_of (wxUniChar ch, size_t nStart=0) const
size_t find_last_not_of (const wxString &str, size_t nStart=npos) const
size_t find_last_not_of (const char *sz, size_t nStart=npos) const
size_t find_last_not_of (const wchar_t *sz, size_t nStart=npos) const
size_t find_last_not_of (const char *sz, size_t nStart, size_t n) const
size_t find_last_not_of (const wchar_t *sz, size_t nStart, size_t n) const
wxStringinsert (size_t nPos, const wxString &str)
wxStringinsert (size_t nPos, const wxString &str, size_t nStart, size_t n)
wxStringinsert (size_t nPos, const char *sz, size_t n)
wxStringinsert (size_t nPos, const wchar_t *sz, size_t n)
wxStringinsert (size_t nPos, size_t n, wxUniChar ch)
iterator insert (iterator it, wxUniChar ch)
void insert (iterator it, const_iterator first, const_iterator last)
void insert (iterator it, size_type n, wxUniChar ch)
size_t length () const
size_type max_size () const
void reserve (size_t sz)
void resize (size_t nSize, wxUniChar ch='\0')
wxStringreplace (size_t nStart, size_t nLen, const wxString &str)
wxStringreplace (size_t nStart, size_t nLen, size_t nCount, wxUniChar ch)
wxStringreplace (size_t nStart, size_t nLen, const wxString &str, size_t nStart2, size_t nLen2)
wxStringreplace (size_t nStart, size_t nLen, const char *sz, size_t nCount)
wxStringreplace (size_t nStart, size_t nLen, const wchar_t *sz, size_t nCount)
wxStringreplace (size_t nStart, size_t nLen, const wxString &s, size_t nCount)
wxStringreplace (iterator first, iterator last, const wxString &s)
wxStringreplace (iterator first, iterator last, const char *s, size_type n)
wxStringreplace (iterator first, iterator last, const wchar_t *s, size_type n)
wxStringreplace (iterator first, iterator last, size_type n, wxUniChar ch)
wxStringreplace (iterator first, iterator last, const_iterator first1, const_iterator last1)
wxStringreplace (iterator first, iterator last, const char *first1, const char *last1)
wxStringreplace (iterator first, iterator last, const wchar_t *first1, const wchar_t *last1)
size_t rfind (const wxString &str, size_t nStart=npos) const
size_t rfind (const char *sz, size_t nStart=npos, size_t n=npos) const
size_t rfind (const wchar_t *sz, size_t nStart=npos, size_t n=npos) const
size_t rfind (wxUniChar ch, size_t nStart=npos) const
size_type size () const
wxString substr (size_t nStart=0, size_t nLen=npos) const
void swap (wxString &str)
bool starts_with (const wxString &str) const
bool starts_with (const char *sz) const
bool starts_with (const wchar_t *sz) const
bool ends_with (const wxString &str) const
bool ends_with (const char *sz) const
bool ends_with (const wchar_t *sz) const
static wxString Format (const wxString &format,...)
 This static function returns the string containing the result of calling Printf() with the passed parameters on it.
static wxString FormatV (const wxString &format, va_list argptr)
 This static function returns the string containing the result of calling PrintfV() with the passed parameters on it.
*static wxString From8BitData (const char *buf)
**static wxString FromAscii (const unsigned char *s)
static wxString FromAscii (const char *s, size_t len)
static wxString FromAscii (const unsigned char *s, size_t len)
static wxString FromAscii (char c)
*static wxString FromCDouble (double val, int precision=-1)
 Returns a string with the textual representation of the number in C locale.
static wxString FromDouble (double val, int precision=-1)
 Returns a string with the textual representation of the number.
*static wxString FromUTF8 (const char *s, size_t len)
static wxString FromUTF8 (const std::string &s)
static wxString FromUTF8 (std::string_view s)
**static wxString FromUTF8Unchecked (const char *s, size_t len)
static wxString FromUTF8Unchecked (const std::string &s)
static wxString FromUTF8Unchecked (std::string_view s)
*wxString wxASCII_STR (const char *s)
 Convenience macro for explicitly constructing wxString from ASCII strings.
Constructors and assignment operators

A string may be constructed either from a C string, (some number of copies of) a single character or a wide (Unicode) string. For all constructors (except the default which creates an empty string) there is also a corresponding assignment operator.

See also the assign() STL-like function.

 wxString ()
 Default constructor.
 wxString (const wxString &stringSrc)
 Creates a string from another string.
 wxString (wxUniChar ch, size_t nRepeat=1)
 Construct a string consisting of nRepeat copies of ch.
 wxString (wxUniCharRef ch, size_t nRepeat=1)
 Construct a string consisting of nRepeat copies of ch.
 wxString (char ch, size_t nRepeat=1)
 Construct a string consisting of nRepeat copies of ch converted to Unicode using the current locale encoding.
 wxString (wchar_t ch, size_t nRepeat=1)
 Construct a string consisting of nRepeat copies of ch.
 wxString (const char *psz)
 Constructs a string from the string literal psz using the current locale encoding to convert it to Unicode (wxConvLibc).
 wxString (const char *psz, const wxMBConv &conv)
 Constructs a string from the string literal psz using conv to convert it Unicode.
 wxString (const char *psz, size_t nLength)
 Constructs a string from the first nLength bytes of the string literal psz using the current locale encoding to convert it to Unicode (wxConvLibc).
 wxString (const char *psz, const wxMBConv &conv, size_t nLength)
 Constructs a string from the first nLength bytes of the string literal psz using conv to convert it Unicode.
 wxString (const wchar_t *pwz)
 Constructs a string from the string literal pwz.
 wxString (const wchar_t *pwz, size_t nLength)
 Constructs a string from the first nLength characters of the string literal pwz.
 wxString (const wxCharBuffer &buf)
 Constructs a string from buf using the using the current locale encoding to convert it to Unicode.
 wxString (const wxWCharBuffer &buf)
 Constructs a string from buf.
 wxString (const std::string &str)
 Constructs a string from str using the using the current locale encoding to convert it to Unicode (wxConvLibc).
 wxString (std::string_view str)
 Constructs a string from str using the using the current locale encoding to convert it to Unicode (wxConvLibc).
 wxString (const std::wstring &str)
 Constructs a string from str.
 wxString (std::wstring_view str)
 Constructs a string from str.
 ~wxString ()
 String destructor.
wxString operator= (const wxString &str)
 Assignment: see the relative wxString constructor.
wxString operator= (wxUniChar c)
 Assignment: see the relative wxString constructor.
void AssignFromUTF8Unchecked (const char *utf8, size_t len=npos)
 Assignment from UTF-8 string.

Variables

*static const size_t npos
 An 'invalid' value for string index.
*wxString wxEmptyString
 The global wxString instance of an empty string.
class wxStringBufferLength Len () const
 @member_group_name{string_length, String length}

Typedef Documentation

◆ char_type

◆ const_pointer

typedef const wxChar* const_pointer

◆ const_reference

◆ pointer

typedef wxChar* pointer

◆ reference

◆ size_type

typedef size_t size_type

◆ value_type

Function Documentation

◆ AfterFirst()

wxString AfterFirst ( wxUniChar ch) const

Gets all the characters after the first occurrence of ch.

Returns the empty string if ch is not found.

◆ AfterLast()

wxString AfterLast ( wxUniChar ch) const

Gets all the characters after the last occurrence of ch.

Returns the whole string if ch is not found.

◆ Append() [1/5]

wxString & Append ( const char * psz,
size_t nLen )

Appends the string literal psz with max length nLen.

◆ Append() [2/5]

**wxString & Append ( const wchar_t * pwz)

@member_group_name{string_concat, Concatenation}

Almost anything may be concatenated (appended to) with a string!

Note that the various operator<<() overloads work as C++ stream insertion operators. They insert the given value into the string. Precision and format cannot be set using them. Use Printf() instead.

See also the insert() and append() STL-like functions. Appends the wide string literal pwz.

◆ Append() [3/5]

wxString & Append ( const wchar_t * pwz,
size_t nLen )

Appends the wide string literal psz with max length nLen.

◆ Append() [4/5]

wxString & Append ( const wxString & s)

Appends the string s.

◆ Append() [5/5]

wxString & Append ( wxUniChar ch,
size_t count = 1u )

Appends the character ch count times.

◆ append() [1/5]

wxString & append ( const char * sz,
size_t n )

◆ append() [2/5]

wxString & append ( const wchar_t * sz,
size_t n )

◆ append() [3/5]

**wxString & append ( const wxString & str)

@member_group_name{string_stl, STL interface}

The supported STL functions are listed here.

Please see any STL reference (e.g. http://www.cppreference.com/wiki/string/start) for their documentation.

◆ append() [4/5]

wxString & append ( const_iterator first,
const_iterator last )

◆ append() [5/5]

wxString & append ( size_t n,
wxUniChar ch )

◆ assign() [1/6]

wxString & assign ( const char * sz,
size_t n )

◆ assign() [2/6]

wxString & assign ( const wchar_t * sz,
size_t n )

◆ assign() [3/6]

wxString & assign ( const wxString & str)

◆ assign() [4/6]

wxString & assign ( const wxString & str,
size_t pos,
size_t n )

◆ assign() [5/6]

wxString & assign ( const_iterator first,
const_iterator last )

◆ assign() [6/6]

wxString & assign ( size_t n,
wxUniChar ch )

◆ AssignFromUTF8Unchecked()

void Len::AssignFromUTF8Unchecked ( const char * utf8,
size_t len = npos )

Assignment from UTF-8 string.

Calling s.AssignFromUTF8(utf8, len) is equivalent to doing s = wxString::FromUTF8(utf8, len)` but may be more efficient as it can reuse the existing string buffer instead of always having to allocate a new one.

This function can be useful in performance-sensitive loops or with static variables (retaining their buffer between calls) in often called functions.

Since
3.3.2 */ void AssignFromUTF8(const char *utf8, size_t len = npos);

/** Assignment from UTF-8 string.

This function is the same as AssignFromUTF8() but doesn't check that utf8 is a valid pointer to a valid UTF-8 string. It must not be called if utf8 is @NULL or its contents is not already known to be correct UTF-8.

Since
3.3.2

◆ at()

wxUniCharRef at ( size_t n) const

◆ BeforeFirst()

wxString BeforeFirst ( wxUniChar ch,
wxString * rest = nullptr ) const

Gets all characters before the first occurrence of ch.

Returns the whole string if ch is not found.

Parameters
chThe character to look for.
restFilled with the part of the string following the first occurrence of ch or cleared if it was not found. The same string is returned by AfterFirst() but it is more efficient to use this output parameter if both the "before" and "after" parts are needed than calling both functions one after the other. This parameter is available in wxWidgets version 2.9.2 and later only. Since wxWidgets 3.3.0, this parameter can be equal to the string on which this function is called.
Returns
Part of the string before the first occurrence of ch.

◆ BeforeLast()

wxString BeforeLast ( wxUniChar ch,
wxString * rest = nullptr ) const

Gets all characters before the last occurrence of ch.

Returns the empty string if ch is not found.

Parameters
chThe character to look for.
restFilled with the part of the string following the last occurrence of ch or the copy of this string if it was not found. The same string is returned by AfterLast() but it is more efficient to use this output parameter if both the "before" and "after" parts are needed than calling both functions one after the other. This parameter is available in wxWidgets version 2.9.2 and later only.
Returns
Part of the string before the last occurrence of ch.

◆ begin()

**iterator begin ( )

@member_group_name{string_iter, Iterator interface}

These methods return iterators to the beginning or end of the string.

Please see any STL reference (e.g. http://www.cppreference.com/wiki/string/start) for their documentation.

◆ capacity()

size_type capacity ( ) const

◆ cbegin()

const_iterator cbegin ( ) const

◆ cend()

const_iterator cend ( ) const

◆ char_str()

**wxWritableCharBuffer char_str ( const wxMBConv & conv = wxConvLibc) const

@member_group_name{string_convs, Conversions}

This section contains both implicit and explicit conversions to C style strings. Although implicit conversion is quite convenient, you are advised to use wc_str() for the sake of clarity. Returns an object with string data that is implicitly convertible to char* pointer. Note that any change to the returned buffer is lost and so this function is only usable for passing strings to legacy libraries that don't have const-correct API. Use wxStringBuffer if you want to modify the string.

See also
c_str()

◆ Clear()

void Clear ( )

Clears the string's content, setting its length to zero.

This is the same as clear() and does not free the memory used by the string. To do this, call standard-like shrink_to_fit() or Shrink() after calling this function.

See also
Empty()

◆ clear()

void clear ( )

◆ Clone()

wxString Clone ( ) const

Returns a copy of the string.

This method is obsolete as wxString doesn't use reference-counted implementation any longer and so all string copies are deep and assignment operator or copy constructor can be used instead of this function.

Since
2.9.0

◆ CmpNoCase()

**int CmpNoCase ( const wxString & s) const

@member_group_name{string_cmp, Comparison}

The default comparison function Cmp() is case-sensitive and so is the default version of IsSameAs(). For case insensitive comparisons you should use CmpNoCase() or give a second parameter to IsSameAs(). This last function is maybe more convenient if only equality of the strings matters because it returns a boolean @true value if the strings are the same and not 0 (which is usually @false in C) as Cmp() does.

Matches() is a poor man's regular expression matcher: it only understands '*' and '?' metacharacters in the sense of DOS command line interpreter.

StartsWith() is helpful when parsing a line of text which should start with some predefined prefix and is more efficient than doing direct string comparison as you would also have to precalculate the length of the prefix.

See also the compare() STL-like function. Case-insensitive comparison. Returns a positive value if the string is greater than the argument, zero if it is equal to it or a negative value if it is less than the argument (same semantics as the standard strcmp() function).

See also
Cmp(), IsSameAs().

◆ compare() [1/5]

int compare ( const wxString & str) const

◆ compare() [2/5]

int compare ( size_t nStart,
size_t nLen,
const char * sz,
size_t nCount = npos ) const

◆ compare() [3/5]

int compare ( size_t nStart,
size_t nLen,
const wchar_t * sz,
size_t nCount = npos ) const

◆ compare() [4/5]

int compare ( size_t nStart,
size_t nLen,
const wxString & str ) const

◆ compare() [5/5]

int compare ( size_t nStart,
size_t nLen,
const wxString & str,
size_t nStart2,
size_t nLen2 ) const

◆ crbegin()

const_reverse_iterator crbegin ( ) const

◆ crend()

const_reverse_iterator crend ( ) const

◆ data()

wxCStrData data ( ) const

◆ Empty()

**void Empty ( )

@member_group_name{string_misc, Miscellaneous}

Miscellaneous other string functions. This is a synonym for Clear().

Prefer using clear() instead of this function in new code, especially considering that this function is very different from the standard empty() function.

◆ empty()

bool empty ( ) const

◆ end()

iterator end ( ) const

◆ ends_with() [1/3]

bool ends_with ( const char * sz) const

◆ ends_with() [2/3]

bool ends_with ( const wchar_t * sz) const

◆ ends_with() [3/3]

bool ends_with ( const wxString & str) const

◆ EndsWith()

bool EndsWith ( const wxString & suffix,
wxString * rest = nullptr ) const

This function can be used to test if the string ends with the specified suffix.

If it does, the function will return @true and put the beginning of the string before the suffix into rest string if it is not @NULL. Otherwise, the function returns @false and doesn't modify the rest.

◆ erase() [1/3]

iterator erase ( iterator first)

◆ erase() [2/3]

iterator erase ( iterator first,
iterator last )

◆ erase() [3/3]

wxString & erase ( size_type pos = 0,
size_type n = npos )

◆ Find()

**int Find ( const wxString & sub) const

@member_group_name{string_search, Searching and replacing}

These functions replace the standard strchr() and strstr() functions.

See also the find(), rfind(), replace() STL-like functions. Searches for the given string sub. Returns the starting position or wxNOT_FOUND if not found.

◆ find() [1/4]

size_t find ( const char * sz,
size_t nStart = 0,
size_t n = npos ) const

◆ find() [2/4]

size_t find ( const wchar_t * sz,
size_t nStart = 0,
size_t n = npos ) const

◆ find() [3/4]

size_t find ( const wxString & str,
size_t nStart = 0 ) const

◆ find() [4/4]

size_t find ( wxUniChar ch,
size_t nStart = 0 ) const

◆ find_first_not_of() [1/6]

size_t find_first_not_of ( const char * sz,
size_t nStart,
size_t n ) const

◆ find_first_not_of() [2/6]

size_t find_first_not_of ( const char * sz,
size_t nStart = 0 ) const

◆ find_first_not_of() [3/6]

size_t find_first_not_of ( const wchar_t * sz,
size_t nStart,
size_t n ) const

◆ find_first_not_of() [4/6]

size_t find_first_not_of ( const wchar_t * sz,
size_t nStart = 0 ) const

◆ find_first_not_of() [5/6]

size_t find_first_not_of ( const wxString & str,
size_t nStart = 0 ) const

◆ find_first_not_of() [6/6]

size_t find_first_not_of ( wxUniChar ch,
size_t nStart = 0 ) const

◆ find_first_of() [1/5]

size_t find_first_of ( const char * sz,
size_t nStart,
size_t n ) const

◆ find_first_of() [2/5]

size_t find_first_of ( const char * sz,
size_t nStart = 0 ) const

◆ find_first_of() [3/5]

size_t find_first_of ( const wchar_t * sz,
size_t nStart,
size_t n ) const

◆ find_first_of() [4/5]

size_t find_first_of ( const wchar_t * sz,
size_t nStart = 0 ) const

◆ find_first_of() [5/5]

size_t find_first_of ( wxUniChar c,
size_t nStart = 0 ) const

◆ find_last_not_of() [1/5]

size_t find_last_not_of ( const char * sz,
size_t nStart,
size_t n ) const

◆ find_last_not_of() [2/5]

size_t find_last_not_of ( const char * sz,
size_t nStart = npos ) const

◆ find_last_not_of() [3/5]

size_t find_last_not_of ( const wchar_t * sz,
size_t nStart,
size_t n ) const

◆ find_last_not_of() [4/5]

size_t find_last_not_of ( const wchar_t * sz,
size_t nStart = npos ) const

◆ find_last_not_of() [5/5]

size_t find_last_not_of ( const wxString & str,
size_t nStart = npos ) const

◆ find_last_of() [1/6]

size_t find_last_of ( const char * sz,
size_t nStart,
size_t n ) const

◆ find_last_of() [2/6]

size_t find_last_of ( const char * sz,
size_t nStart = npos ) const

◆ find_last_of() [3/6]

size_t find_last_of ( const wchar_t * sz,
size_t nStart,
size_t n ) const

◆ find_last_of() [4/6]

size_t find_last_of ( const wchar_t * sz,
size_t nStart = npos ) const

◆ find_last_of() [5/6]

size_t find_last_of ( const wxString & str,
size_t nStart = npos ) const

◆ find_last_of() [6/6]

size_t find_last_of ( wxUniChar c,
size_t nStart = npos ) const

◆ First() [1/2]

int First ( const wxString & str) const

Same as Find().

This is a wxWidgets 1.xx compatibility function; you should not use it in new code.

◆ First() [2/2]

int First ( wxUniChar ch) const

Same as Find().

This is a wxWidgets 1.xx compatibility function; you should not use it in new code.

◆ fn_str()

const TYPE fn_str ( ) const

Returns a string representation suitable for passing to OS' functions for file handling.

Depending on OS and configuration, TYPE is either wchar_t*, char*, or wxCharBuffer.

◆ Format()

wxString Format ( const wxString & format,
... )
static

This static function returns the string containing the result of calling Printf() with the passed parameters on it.

See also
FormatV(), Printf()

◆ FormatV()

wxString FormatV ( const wxString & format,
va_list argptr )
static

This static function returns the string containing the result of calling PrintfV() with the passed parameters on it.

See also
Format(), PrintfV()

◆ Freq()

int Freq ( wxUniChar ch) const

Returns the number of occurrences of ch in the string.

This is a wxWidgets 1.xx compatibility function; you should not use it in new code.

◆ From8BitData()

*static wxString From8BitData ( const char * buf)
static

◆ FromAscii() [1/4]

wxString FromAscii ( char c)
static

◆ FromAscii() [2/4]

wxString FromAscii ( const char * s,
size_t len )
static

◆ FromAscii() [3/4]

**static wxString FromAscii ( const unsigned char * s)
static

◆ FromAscii() [4/4]

wxString FromAscii ( const unsigned char * s,
size_t len )
static

◆ FromCDouble()

*static wxString FromCDouble ( double val,
int precision = -1 )
static

Returns a string with the textual representation of the number in C locale.

Unlike FromDouble() the string returned by this function always uses the period character as decimal separator, independently of the current locale. Otherwise its behaviour is identical to the other function.

Since
2.9.1
See also
ToCDouble()

◆ FromDouble()

wxString FromDouble ( double val,
int precision = -1 )
static

Returns a string with the textual representation of the number.

For the default value of precision, this function behaves as a simple wrapper for

wxString::Format("%g", val)

. If precision is positive (or zero), the %.Nf format is used with the given precision value.

Notice that the string returned by this function uses the decimal separator appropriate for the current locale, e.g. "," and not a period in French locale. Use FromCDouble() if this is unwanted.

Parameters
valThe value to format.
precisionThe number of fractional digits to use in or -1 to use the most appropriate format. This parameter is new in wxWidgets 2.9.2.
Since
2.9.1
See also
ToDouble()

◆ FromUTF8() [1/3]

*static wxString FromUTF8 ( const char * s,
size_t len )
static

◆ FromUTF8() [2/3]

wxString FromUTF8 ( const std::string & s)
static

◆ FromUTF8() [3/3]

wxString FromUTF8 ( std::string_view s)
static

◆ FromUTF8Unchecked() [1/3]

**static wxString FromUTF8Unchecked ( const char * s,
size_t len )
static

◆ FromUTF8Unchecked() [2/3]

wxString FromUTF8Unchecked ( const std::string & s)
static

◆ FromUTF8Unchecked() [3/3]

wxString FromUTF8Unchecked ( std::string_view s)
static

◆ GetData()

**const wxCStrData GetData ( ) const

@member_group_name{string_ch_access, Character access}

Many functions below take a character index in the string. As with C strings and arrays, the indices start from 0, so the first character of a string is string[0]. An attempt to access a character beyond the end of the string (which may even be 0 if the string is empty) will provoke an assert failure in debug builds, but no checks are done in release builds. wxWidgets compatibility conversion. Same as c_str().

◆ GetWritableChar()

wxUniCharRef GetWritableChar ( size_t n)

Returns a reference to the character at position n.

◆ insert() [1/8]

void insert ( iterator it,
const_iterator first,
const_iterator last )

◆ insert() [2/8]

void insert ( iterator it,
size_type n,
wxUniChar ch )

◆ insert() [3/8]

iterator insert ( iterator it,
wxUniChar ch )

◆ insert() [4/8]

wxString & insert ( size_t nPos,
const char * sz,
size_t n )

◆ insert() [5/8]

wxString & insert ( size_t nPos,
const wchar_t * sz,
size_t n )

◆ insert() [6/8]

wxString & insert ( size_t nPos,
const wxString & str )

◆ insert() [7/8]

wxString & insert ( size_t nPos,
const wxString & str,
size_t nStart,
size_t n )

◆ insert() [8/8]

wxString & insert ( size_t nPos,
size_t n,
wxUniChar ch )

◆ IsAscii()

bool IsAscii ( ) const

Returns @true if the string contains only ASCII characters.

See wxUniChar::IsAscii for more details.

This is a wxWidgets 1.xx compatibility function; you should not use it in new code.

◆ IsEmpty()

bool IsEmpty ( ) const

Returns @true if the string is empty.

◆ IsNull()

bool IsNull ( ) const

Returns @true if the string is empty (same as wxString::IsEmpty).

This is a wxWidgets 1.xx compatibility function; you should not use it in new code.

◆ IsNumber()

bool IsNumber ( ) const

Returns @true if the string is an integer (with possible sign).

This is a wxWidgets 1.xx compatibility function; you should not use it in new code.

◆ IsSameAs() [1/2]

bool IsSameAs ( const wxString & s,
bool caseSensitive = true ) const

Test whether the string is equal to another string s.

The test is case-sensitive if caseSensitive is @true (default) or not if it is @false.

Returns
@true if the string is equal to the other one, @false otherwise.
See also
Cmp(), CmpNoCase()

◆ IsSameAs() [2/2]

bool IsSameAs ( wxUniChar ch,
bool caseSensitive = true ) const

Test whether the string is equal to the single character ch.

The test is case-sensitive if caseSensitive is @true (default) or not if it is @false.

Returns
@true if the string is equal to this character, @false otherwise.
See also
Cmp(), CmpNoCase()

◆ IsWord()

bool IsWord ( ) const

Returns @true if the string is a word.

This is a wxWidgets 1.xx compatibility function; you should not use it in new code.

◆ Last()

wxUniCharRef Last ( ) const

Returns the last character.

Returns a reference to the last character (writable).

This is a wxWidgets 1.xx compatibility function; you should not use it in new code.

◆ Left()

wxString Left ( size_t count) const

Returns the first count characters of the string.

◆ Length()

size_t Length ( ) const

Returns the length of the string (same as Len).

This is a wxWidgets 1.xx compatibility function; you should not use it in new code.

◆ length()

size_t length ( ) const

◆ Lower()

**wxString Lower ( ) const

@member_group_name{string_caseconv, Case conversion}

The MakeXXX() variants modify the string in place, while the other functions return a new string which contains the original text converted to the upper or lower case and leave the original string unchanged. Returns this string converted to the lower case.

See also
MakeLower()

◆ LowerCase()

void LowerCase ( )

Same as MakeLower.

This is a wxWidgets 1.xx compatibility function; you should not use it in new code.

◆ MakeCapitalized()

wxString & MakeCapitalized ( )

Converts the first characters of the string to the upper case and all the subsequent ones to the lower case and returns the result.

Since
2.9.0
See also
Capitalize()

◆ MakeLower()

wxString & MakeLower ( )

Converts all characters to lower case and returns the reference to the modified string.

See also
Lower()

◆ MakeUpper()

wxString & MakeUpper ( )

Converts all characters to upper case and returns the reference to the modified string.

See also
Upper()

◆ Matches()

*bool Matches ( const wxString & mask) const

Returns @true if the string contents matches a mask containing '*' and '?

'.

◆ max_size()

size_type max_size ( ) const

◆ mb_str()

const wxCharBuffer mb_str ( const wxMBConv & conv = wxConvLibc) const

Returns the multibyte (C string) representation of the string using conv's wxMBConv::cWC2MB method and returns wxCharBuffer.

See also
wc_str(), utf8_str(), c_str(), wxMBConv

◆ operator!()

bool operator! ( ) const

Empty string is @false, so !string will only return @true if the string is empty.

See also
IsEmpty().

◆ operator!=() [1/16]

friend bool operator!= ( char c,
const wxString & s )

◆ operator!=() [2/16]

friend bool operator!= ( const wxCharBuffer & s1,
const wxString & s2 )

◆ operator!=() [3/16]

friend bool operator!= ( const wxCStrData & s1,
const wxString & s2 )

◆ operator!=() [4/16]

friend bool operator!= ( const wxString & s,
char c )

◆ operator!=() [5/16]

friend bool operator!= ( const wxString & s,
const wxUniChar & c )

◆ operator!=() [6/16]

friend bool operator!= ( const wxString & s,
const wxUniCharRef & c )

◆ operator!=() [7/16]

friend bool operator!= ( const wxString & s,
wchar_t c )

◆ operator!=() [8/16]

friend bool operator!= ( const wxString & s1,
const wxCharBuffer & s2 )

◆ operator!=() [9/16]

friend bool operator!= ( const wxString & s1,
const wxCStrData & s2 )

◆ operator!=() [10/16]

*friend bool operator!= ( const wxString & s1,
const wxString & s2 )

◆ operator!=() [11/16]

friend bool operator!= ( const wxString & s1,
const wxWCharBuffer & s2 )

◆ operator!=() [12/16]

friend bool operator!= ( const wxUniChar & c,
const wxString & s )

◆ operator!=() [13/16]

friend bool operator!= ( const wxUniCharRef & c,
const wxString & s )

◆ operator!=() [14/16]

friend bool operator!= ( const wxWCharBuffer & s1,
const wxString & s2 )

◆ operator!=() [15/16]

friend bool operator!= ( int c,
const wxString & s )

◆ operator!=() [16/16]

friend bool operator!= ( wchar_t c,
const wxString & s )

◆ operator()()

wxString operator() ( size_t start,
size_t len ) const

Same as Mid() (substring extraction).

◆ operator+() [1/2]

friend wxString operator+ ( const wxString & x,
const wxString & y )

Concatenation: returns a new string equal to the concatenation of the operands.

◆ operator+() [2/2]

friend wxString operator+ ( const wxString & x,
wxUniChar y )

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

◆ operator+=() [1/2]

void operator+= ( const wxString & str)

Concatenation in place: the argument is appended to the string.

◆ operator+=() [2/2]

void operator+= ( wxUniChar c)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

◆ operator<()

friend bool operator< ( const wxString & s1,
const wxString & s2 )

◆ operator<<() [1/18]

wxString & operator<< ( char ch)

◆ operator<<() [2/18]

wxString & operator<< ( const char * psz)

◆ operator<<() [3/18]

wxString & operator<< ( const wchar_t * pwz)

◆ operator<<() [4/18]

wxString & operator<< ( const wxCharBuffer & s)

◆ operator<<() [5/18]

wxString & operator<< ( const wxCStrData & psz)

◆ operator<<() [6/18]

wxString & operator<< ( const wxString & s)

◆ operator<<() [7/18]

wxString & operator<< ( const wxWCharBuffer & s)

◆ operator<<() [8/18]

wxString & operator<< ( double d)

◆ operator<<() [9/18]

wxString & operator<< ( float f)

◆ operator<<() [10/18]

wxString & operator<< ( long l)

◆ operator<<() [11/18]

wxString & operator<< ( unsigned char ch)

◆ operator<<() [12/18]

wxString & operator<< ( unsigned int ui)

◆ operator<<() [13/18]

wxString & operator<< ( unsigned long ul)

◆ operator<<() [14/18]

wxString & operator<< ( wchar_t ch)

◆ operator<<() [15/18]

wxString & operator<< ( wxLongLong_t ll)

◆ operator<<() [16/18]

wxString & operator<< ( wxULongLong_t ul)

◆ operator<<() [17/18]

wxString & operator<< ( wxUniChar ch)

◆ operator<<() [18/18]

wxString & operator<< ( wxUniCharRef ch)

◆ operator<=()

friend bool operator<= ( const wxString & s1,
const wxString & s2 )

◆ operator=() [1/2]

wxString Len::operator= ( const wxString & str)

Assignment: see the relative wxString constructor.

◆ operator=() [2/2]

wxString Len::operator= ( wxUniChar c)

Assignment: see the relative wxString constructor.

◆ operator==() [1/14]

friend bool operator== ( char c,
const wxString & s )

◆ operator==() [2/14]

friend bool operator== ( const wxCharBuffer & s1,
const wxString & s2 )

◆ operator==() [3/14]

friend bool operator== ( const wxCStrData & s1,
const wxString & s2 )

◆ operator==() [4/14]

friend bool operator== ( const wxString & s,
char c )

◆ operator==() [5/14]

friend bool operator== ( const wxString & s,
const wxUniChar & c )

◆ operator==() [6/14]

friend bool operator== ( const wxString & s,
const wxUniCharRef & c )

◆ operator==() [7/14]

friend bool operator== ( const wxString & s,
wchar_t c )

◆ operator==() [8/14]

friend bool operator== ( const wxString & s1,
const wxCharBuffer & s2 )

◆ operator==() [9/14]

friend bool operator== ( const wxString & s1,
const wxCStrData & s2 )

◆ operator==() [10/14]

friend bool operator== ( const wxString & s1,
const wxWCharBuffer & s2 )

◆ operator==() [11/14]

**friend bool operator== ( const wxUniCharRef & c,
const wxString & s )

◆ operator==() [12/14]

friend bool operator== ( const wxWCharBuffer & s1,
const wxString & s2 )

◆ operator==() [13/14]

friend bool operator== ( int c,
const wxString & s )

◆ operator==() [14/14]

friend bool operator== ( wchar_t c,
const wxString & s )

◆ operator>()

friend bool operator> ( const wxString & s1,
const wxString & s2 )

◆ operator>=()

friend bool operator>= ( const wxString & s1,
const wxString & s2 )

◆ operator[]()

wxUniCharRef operator[] ( size_t i) const

Returns the i-th character of the string.

Returns a writable reference to the i-th character of the string.

◆ Pad()

wxString & Pad ( size_t count,
wxUniChar chPad = ' ',
bool fromRight = true )

Adds count copies of chPad to the beginning, or to the end of the string (the default).

By default, appends the given number of spaces to the string. The character being added and whether it is appended or prepended can be changed by providing non-default parameter values.

◆ Prepend()

wxString & Prepend ( const wxString & str)

Prepends str to this string, returning a reference to this string.

◆ PrintfV()

**int PrintfV ( const wxString & pszFormat,
va_list argPtr )

@member_group_name{string_fmt, Formatting and printing}

Both formatted versions (Printf/() and stream-like insertion operators exist (for basic types only).

See also the static Format() and FormatV() functions. Similar to vprintf. Returns the number of characters written, or an integer less than zero on error.

◆ rbegin()

reverse_iterator rbegin ( ) const

◆ Remove() [1/2]

wxString & Remove ( size_t pos)

Removes all characters from the string starting at pos.

Use Truncate() as a more readable alternative.

This is a wxWidgets 1.xx compatibility function; you should not use it in new code.

◆ Remove() [2/2]

wxString & Remove ( size_t pos,
size_t len )

Removes len characters from the string, starting at pos.

This is a wxWidgets 1.xx compatibility function; you should not use it in new code.

◆ RemoveLast()

wxString & RemoveLast ( size_t n = 1)

Removes the last character.

◆ rend()

reverse_iterator rend ( ) const

◆ Replace()

size_t Replace ( const wxString & strOld,
const wxString & strNew,
bool replaceAll = true )

Replace first (or all) occurrences of substring with another one.

Parameters
strOldThe string to search for replacing.
strNewThe substitution string.
replaceAllIf @true a global replace will be done (default), otherwise only the first occurrence will be replaced.

Returns the number of replacements made.

◆ replace() [1/13]

wxString & replace ( iterator first,
iterator last,
const char * first1,
const char * last1 )

◆ replace() [2/13]

wxString & replace ( iterator first,
iterator last,
const char * s,
size_type n )

◆ replace() [3/13]

wxString & replace ( iterator first,
iterator last,
const wchar_t * first1,
const wchar_t * last1 )

◆ replace() [4/13]

wxString & replace ( iterator first,
iterator last,
const wchar_t * s,
size_type n )

◆ replace() [5/13]

wxString & replace ( iterator first,
iterator last,
const wxString & s )

◆ replace() [6/13]

wxString & replace ( iterator first,
iterator last,
const_iterator first1,
const_iterator last1 )

◆ replace() [7/13]

wxString & replace ( iterator first,
iterator last,
size_type n,
wxUniChar ch )

◆ replace() [8/13]

wxString & replace ( size_t nStart,
size_t nLen,
const char * sz,
size_t nCount )

◆ replace() [9/13]

wxString & replace ( size_t nStart,
size_t nLen,
const wchar_t * sz,
size_t nCount )

◆ replace() [10/13]

wxString & replace ( size_t nStart,
size_t nLen,
const wxString & s,
size_t nCount )

◆ replace() [11/13]

wxString & replace ( size_t nStart,
size_t nLen,
const wxString & str )

◆ replace() [12/13]

wxString & replace ( size_t nStart,
size_t nLen,
const wxString & str,
size_t nStart2,
size_t nLen2 )

◆ replace() [13/13]

wxString & replace ( size_t nStart,
size_t nLen,
size_t nCount,
wxUniChar ch )

◆ reserve()

void reserve ( size_t sz)

◆ resize()

void resize ( size_t nSize,
wxUniChar ch = '\0' )

◆ rfind() [1/4]

size_t rfind ( const char * sz,
size_t nStart = npos,
size_t n = npos ) const

◆ rfind() [2/4]

size_t rfind ( const wchar_t * sz,
size_t nStart = npos,
size_t n = npos ) const

◆ rfind() [3/4]

size_t rfind ( const wxString & str,
size_t nStart = npos ) const

◆ rfind() [4/4]

size_t rfind ( wxUniChar ch,
size_t nStart = npos ) const

◆ Right()

wxString Right ( size_t count) const

Returns the last count characters.

◆ SetChar()

void SetChar ( size_t n,
wxUniChar ch )

Sets the character at position n.

◆ Shrink()

**bool Shrink ( )

@member_group_name{string_mem, Memory management}

The following are "advanced" functions and they will be needed rarely. Alloc() and Shrink() are only interesting for optimization purposes. wxStringBuffer and wxStringBufferLength classes may be very useful when working with some external API which requires the caller to provide a writable buffer.

See also the reserve(), resize() and shrink_to_fit() STL-like functions. Minimizes the string's memory.

Please note that this method does the same thing as the standard shrink_to_fit() one and shouldn't be used in new code.

This can be useful after a call to Alloc() if too much memory were preallocated.

Returns
Always returns @true

◆ size()

size_type size ( ) const

◆ starts_with() [1/3]

bool starts_with ( const char * sz) const

◆ starts_with() [2/3]

bool starts_with ( const wchar_t * sz) const

◆ starts_with() [3/3]

bool starts_with ( const wxString & str) const

◆ StartsWith()

bool StartsWith ( const wxString & prefix,
wxString * rest = nullptr ) const

This function can be used to test if the string starts with the specified prefix.

If it does, the function will return @true and put the rest of the string (i.e. after the prefix) into rest string if it is not @NULL. Otherwise, the function returns @false and doesn't modify the rest.

◆ Strip()

wxString Strip ( stripType s = trailing) const

Strip characters at the front and/or end.

This is the same as Trim() except that it doesn't change this string.

This is a wxWidgets 1.xx compatibility function; you should not use it in new code.

◆ substr()

wxString substr ( size_t nStart = 0,
size_t nLen = npos ) const

◆ SubString()

**wxString SubString ( size_t from,
size_t to ) const

@member_group_name{string_substring, Substring extraction}

These functions allow you to extract a substring from the string. The original string is not modified and the function returns the extracted substring.

See also the at() and the substr() STL-like functions. Returns the part of the string between the indices from and to inclusive.

This is a wxWidgets 1.xx compatibility function, use Mid() instead (but note that parameters have different meaning).

◆ swap()

void swap ( wxString & str)

◆ tchar_str()

template<typename T>
wxCharTypeBuffer< T > tchar_str ( size_t * len = nullptr) const

Returns buffer of the specified type containing the string data.

This method is only useful in template code, otherwise you should directly call mb_str() or wc_str() if you need to retrieve a narrow or wide string from this wxString. The template parameter t should be either char or wchar_t.

Notice that retrieving a char buffer in UTF-8 build will return the internal string representation in UTF-8 while in wchar_t build the char buffer will contain the conversion of the string to the encoding of the current locale (and so can fail).

Parameters
lenIf non-null, filled with the length of the returned buffer.
Returns
buffer containing the string contents in the specified type, notice that it may be @NULL if the conversion failed (e.g. Unicode string couldn't be converted to the current encoding when T is char).

◆ To8BitData()

const wxScopedCharBuffer To8BitData ( ) const

Converts the string to an 8-bit string in ISO-8859-1 encoding in the form of a wxCharBuffer.

Note
It is not recommended to use wxString for storing binary data.

This is a convenience method useful when storing binary data in wxString. It should be used only for this purpose. It is only valid to call this method on strings created using From8BitData().

Since
2.8.4
See also
wxString::From8BitData()

◆ ToAscii()

const wxCharBuffer ToAscii ( char replaceWith = '_') const

Converts the string to an ASCII, 7-bit string.

Note that this conversion is only lossless if the string contains only ASCII characters as all the non-ASCII ones are replaced with the (same) provided replacement character.

Use mb_str() or utf8_str() to convert to other encodings.

Parameters
replaceWithThe character used to replace any non-ASCII characters, default to underscore ("_"). This parameter is new since wxWidgets 3.1.0.

◆ ToCDouble()

**bool ToCDouble ( double * val) const

@member_group_name{string_numconv, Conversion to numbers}

The string provides functions for conversion to signed and unsigned integer and floating point numbers.

All functions take a pointer to the variable to put the numeric value in and return @true if the entire string could be converted to a number. Notice if there is a valid number in the beginning of the string, it is returned in the output parameter even if the function returns @false because there is more text following it. Variant of ToDouble(), always working in "C" locale.

Works like ToDouble(), but this function expects the floating point number to be formatted always with the rules dictated by the "C" locale (in particular, the decimal point must be a dot), independently from the current application-wide locale (see wxLocale).

double val(0);
// Will extract 2.2 from the string, but returns
// false because the "lbs" section of the string
// was not part of the conversion.
wxString str("2.2lbs");
bool fullStringConverted = str.ToCDouble(&val);
// Will also extract 2.2, but returns true because
// the entirety of the string was converted to a double.
str.assign("2.2");
fullStringConverted = str.ToCDouble(&val);
String class for passing textual data to or receiving it from wxWidgets.
Definition string.h:372
See also
ToDouble(), ToLong(), ToULong()

◆ ToCLong()

bool ToCLong ( long * val,
int base = 10 ) const

Variant of ToLong() always working in "C" locale.

Works like ToLong() but unlike it this function expects the integer number to be formatted always with the rules dictated by the "C" locale, independently from the current application-wide locale (see wxLocale).

See also
ToDouble(), ToLong(), ToULong()

◆ ToCULong()

bool ToCULong ( unsigned long * val,
int base = 10 ) const

Variant of ToULong() always working in "C" locale.

Works like ToULong() but unlike it this function expects the integer number to be formatted always with the rules dictated by the "C" locale, independently from the current application-wide locale (see wxLocale).

See also
ToDouble(), ToLong(), ToULong()

◆ ToInt()

bool ToInt ( int * val,
int base = 10 ) const

Works like ToLong() but for signed integers.

See also
ToLong(), ToUInt(), ToDouble()
Since
3.1.6

◆ ToLong()

bool ToLong ( long * val,
int base = 10 ) const

Attempts to convert the string to a signed integer in base base.

Returns @true on success in which case the number is stored in the location pointed to by val or @false if the string does not represent a valid number in the given base (the value of val may still be modified in this case).

The value of base must be comprised between 2 and 36, inclusive, or be a special value 0 which means that the usual rules of C numbers are applied: if the number starts with 0x it is considered to be in base 16, if it starts with 0 - in base 8 and in base 10 otherwise. Note that you may not want to specify the base 0 if you are parsing the numbers which may have leading zeroes as they can yield unexpected (to the user not familiar with C) results.

Note that unlike ToCLong() this function uses a localized version of wxStrtol(). Thus you should use this function only when you are sure that this string contains an integer number formatted with the rules of the locale currently in use (see wxLocale).

As with ToDouble(), this function does not support strings containing thousands separators even if the current locale uses digits grouping. You may use wxNumberFormatter::FromString() to parse such strings.

Please refer to the documentation of the standard function strtol() for more details about the supported syntax.

See also
ToCDouble(), ToDouble(), ToULong(), ToInt()

◆ ToLongLong()

bool ToLongLong ( wxLongLong_t * val,
int base = 10 ) const

This is exactly the same as ToLong() but works with 64 bit integer numbers.

Notice that currently it doesn't work (always returns @false) if parsing of 64 bit numbers is not supported by the underlying C run-time library. Compilers with C99 support and Microsoft Visual C++ version 7 and higher do support this.

See also
ToLong(), ToULongLong()

◆ ToStdString()

std::string ToStdString ( const wxMBConv & conv = wxConvLibc) const

Return the string as a std::string using conv's wxMBConv::cWC2MB method.

Note that if the conversion of (Unicode) string contents using conv fails, the return string will be empty. Be sure to check for this to avoid silent data loss. Alternatively, pass wxConvUTF8 as conv or use utf8_string() to always use UTF-8 encoding, rather than the current one.

Instead of using this function it's also possible to write

std::string s;
...
s = std::string(wxs);

but using ToStdString() may make the code more clear.

Parameters
convThe converter to be used. This parameter is new in wxWidgets 3.1.1.
Since
2.9.1

◆ ToStdWstring()

std::wstring ToStdWstring ( ) const

Return the string as a std::wstring.

Unlike ToStdString(), there is no danger of data loss when using this function.

Note that the return type of this function is actually const std::wstring& in wxWidgets builds using wxUSE_UNICODE_WCHAR==1 (which is the default), i.e. in this build there is no copying of string contents, however a temporary copy of the string is returned in wxUSE_UNICODE_UTF8==1 build.

Since
2.9.1
See also
wc_string()

◆ ToUInt()

bool ToUInt ( unsigned int * val,
int base = 10 ) const

Works like ToULong() but for unsigned integers.

See also
ToInt(), ToULong(), ToDouble()
Since
3.1.6

◆ ToULong()

bool ToULong ( unsigned long * val,
int base = 10 ) const

Attempts to convert the string to an unsigned integer in base base.

Returns @true on success in which case the number is stored in the location pointed to by val or @false if the string does not represent a valid number in the given base (the value of val may still be modified in this case).

Please notice that this function behaves in the same way as the standard strtoul() and so it simply converts negative numbers to unsigned representation instead of rejecting them (e.g. -1 is returned as ULONG_MAX).

See ToLong() for the more detailed description of the base parameter (and of the locale-specific behaviour of this function).

See also
ToCULong(), ToDouble(), ToLong()

◆ ToULongLong()

bool ToULongLong ( wxULongLong_t * val,
int base = 10 ) const

This is exactly the same as ToULong() but works with 64 bit integer numbers.

Please see ToLongLong() for additional remarks.

◆ ToUTF8()

const wxScopedCharBuffer ToUTF8 ( ) const

Same as utf8_str().

◆ Trim()

wxString & Trim ( bool fromRight = true)

Removes white-space (space, tabs, form feed, newline and carriage return) from the left or from the right end of the string (right is default).

◆ Truncate()

wxString & Truncate ( size_t len)

Truncate the string to the given length.

◆ Upper()

wxString Upper ( ) const

Returns this string converted to upper case.

See also
MakeUpper()

◆ UpperCase()

void UpperCase ( )

The same as MakeUpper().

This is a wxWidgets 1.xx compatibility function; you should not use it in new code.

◆ utf8_str()

const wxScopedCharBuffer utf8_str ( ) const

Converts the strings contents to UTF-8 and returns it either as a temporary wxCharBuffer object or as a pointer to the internal string contents in UTF-8 build.

See also
wc_str(), c_str(), mb_str()

◆ utf8_string()

const std::string utf8_string ( ) const

Return the string as an std::string using UTF-8 encoding.

This is a shorter and more readable equivalent of calling ToStdString() with wxConvUTF8 argument.

Since
3.1.5

◆ wc_str()

const wxWX2WCbuf wc_str ( ) const

Returns the strings contents as a wide character string.

wxWX2WCbuf is macro which can be either wchar_t* or wxWCharBuffer depending on whether wxUSE_UNICODE_UTF8 is 0 or 1.

See also
utf8_str(), c_str(), mb_str(), fn_str(), wchar_str()

◆ wc_string()

std::wstring wc_string ( ) const

Returns the strings contents as a wide character string.

This is a somewhat more readable synonym for ToStdWstring().

The return type of this function is actually const std::wstring& in wxWidgets builds using wxUSE_UNICODE_WCHAR==1 (which is the default), i.e. in this build there is no copying of string contents, however a temporary copy of the string is returned in wxUSE_UNICODE_UTF8==1 build.

Since
3.3.0

◆ wchar_str()

wxWritableWCharBuffer wchar_str ( ) const

Returns an object with string data that is implicitly convertible to char* pointer.

Note that changes to the returned buffer may or may not be lost (depending on the build) and so this function is only usable for passing strings to legacy libraries that don't have const-correct API. Use wxStringBuffer if you want to modify the string.

See also
mb_str(), wc_str(), fn_str(), c_str(), char_str()

◆ wx_str()

const wxStringCharType * wx_str ( ) const

Explicit conversion to C string in the internal representation (either wchar_t* or UTF-8-encoded char*, depending on the build).

◆ wxASCII_STR()

*wxString wxASCII_STR ( const char * s)

Convenience macro for explicitly constructing wxString from ASCII strings.

This macro simply expands to a call to wxString::FromAscii() but is slightly shorter.

Since
3.1.4

◆ wxString() [1/18]

Len::wxString ( )

Default constructor.

◆ wxString() [2/18]

Len::wxString ( char ch,
size_t nRepeat = 1 )

Construct a string consisting of nRepeat copies of ch converted to Unicode using the current locale encoding.

◆ wxString() [3/18]

Len::wxString ( const char * psz)

Constructs a string from the string literal psz using the current locale encoding to convert it to Unicode (wxConvLibc).

◆ wxString() [4/18]

Len::wxString ( const char * psz,
const wxMBConv & conv )

Constructs a string from the string literal psz using conv to convert it Unicode.

◆ wxString() [5/18]

Len::wxString ( const char * psz,
const wxMBConv & conv,
size_t nLength )

Constructs a string from the first nLength bytes of the string literal psz using conv to convert it Unicode.

◆ wxString() [6/18]

Len::wxString ( const char * psz,
size_t nLength )

Constructs a string from the first nLength bytes of the string literal psz using the current locale encoding to convert it to Unicode (wxConvLibc).

◆ wxString() [7/18]

Len::wxString ( const std::string & str)

Constructs a string from str using the using the current locale encoding to convert it to Unicode (wxConvLibc).

See also
ToStdString()

◆ wxString() [8/18]

Len::wxString ( const std::wstring & str)

Constructs a string from str.

See also
ToStdWstring(), wc_string()

◆ wxString() [9/18]

Len::wxString ( const wchar_t * pwz)

Constructs a string from the string literal pwz.

◆ wxString() [10/18]

Len::wxString ( const wchar_t * pwz,
size_t nLength )

Constructs a string from the first nLength characters of the string literal pwz.

◆ wxString() [11/18]

Len::wxString ( const wxCharBuffer & buf)

Constructs a string from buf using the using the current locale encoding to convert it to Unicode.

◆ wxString() [12/18]

Len::wxString ( const wxString & stringSrc)

Creates a string from another string.

Just increases the ref count by 1.

◆ wxString() [13/18]

Len::wxString ( const wxWCharBuffer & buf)

Constructs a string from buf.

◆ wxString() [14/18]

Len::wxString ( std::string_view str)

Constructs a string from str using the using the current locale encoding to convert it to Unicode (wxConvLibc).

Note
Requires the application to be compiled with C++17
Since
3.3.0

◆ wxString() [15/18]

Len::wxString ( std::wstring_view str)

Constructs a string from str.

Note
Requires the application to be compiled with C++17
Since
3.3.0

◆ wxString() [16/18]

Len::wxString ( wchar_t ch,
size_t nRepeat = 1 )

Construct a string consisting of nRepeat copies of ch.

◆ wxString() [17/18]

Len::wxString ( wxUniChar ch,
size_t nRepeat = 1 )

Construct a string consisting of nRepeat copies of ch.

◆ wxString() [18/18]

Len::wxString ( wxUniCharRef ch,
size_t nRepeat = 1 )

Construct a string consisting of nRepeat copies of ch.

◆ ~wxString()

Len::~wxString ( )

String destructor.

Note that this is not virtual, so wxString must not be inherited from.

Variable Documentation

◆ Len

class wxString Len ( ) const

@member_group_name{string_length, String length}

These functions return the string length and/or check whether the string is empty.

See also the length(), size() or empty() STL-like functions. Returns the length of the string.

◆ npos

* static const size_t npos
static

An 'invalid' value for string index.

◆ wxEmptyString

* wxString wxEmptyString

The global wxString instance of an empty string.

Used extensively in the entire wxWidgets API.