.\" This is a wxWidgets manpage page generated from the XML docs .TH wxString 3wx 2005-02-15 "wxWidgets" "wxWidgets class documentation" .SH NAME wxString \- A string class .SH DESCRIPTION wxString is a class representing a character string. Please see the wxString overview for more information about it. As explained there, wxString implements about 90% of methods of the std::string class (iterators are not supported, nor all methods which use them). These standard functions are not documented in this manual so please see the STL documentation. The behaviour of all these functions is identical to the behaviour described there (except that wxString is sensitive to null character). You may notice that wxString sometimes has many functions which do the same thing like, for example, Length() , Len() and length() which all return the string length. In all cases of such duplication the std::string -compatible method ( length() in this case, always the lowercase version) should be used as it will ensure smoother transition to std::string when wxWidgets starts using it instead of wxString. Also please note that in this manual char is sometimes used instead of wxChar because it hasn't been fully updated yet. Please substitute as necessary and refer to the sources in case of a doubt. .SH "PARENTS" .SH "INCLUDE FILES" wx/string.h .SH MEMBERS .SS wxString () Default constructor. Initializes the string to "" (empty string). .SS wxString (const wxString& x) Copy constructor. .SS wxString (char chsize_t n = 1) Constructs a string of n copies of character ch . .SS wxString (const char* pszsize_t nLength = wxSTRING_MAXLEN) Takes first nLength characters from the C string psz . The default value of wxSTRING_MAXLEN means to take all the string. Note that this constructor may be used even if psz points to a buffer with binary data (i.e. containing NUL characters) as long as you provide the correct value for nLength . However, the default form of it works only with strings without intermediate NUL s because it uses strlen() to calculate the effective length and it would not give correct results otherwise. .SS wxString (const unsigned char* pszsize_t nLength = wxSTRING_MAXLEN) For compilers using unsigned char: takes first nLength characters from the C string psz . The default value of wxSTRING_MAXLEN means take all the string. Note: In Unicode build, all of the above constructors take wchar_t arguments instead of char . .SS wxString (const wchar_t* pszwxMBConv& convsize_t nLength = wxSTRING_MAXLEN) Initializes the string from first nLength characters of wide string. The default value of wxSTRING_MAXLEN means take all the string. In ANSI build, conv 's WC2MB method is called to convert psz to wide string. It is ignored in Unicode build. .SS wxString (const char* pszwxMBConv& convsize_t nLength = wxSTRING_MAXLEN) .SS ~wxString () String destructor. Note that this is not virtual, so wxString must not be inherited from. .SS void Alloc (size_t nLen) Preallocate enough space for wxString to store nLen characters. This function may be used to increase speed when the string is constructed by repeated concatenation as in // delete all vowels from the string wxString DeleteAllVowels(const wxString& original) { wxString result; size_t len = original.length(); result.Alloc(len); for ( size_t n = 0; n < len; n++ ) { if ( strchr("aeuio", tolower(original[n])) == NULL ) result += original[n]; } return result; } because it will avoid the need to reallocate string memory many times (in case of long strings). Note that it does not set the maximal length of a string - it will still expand if more than nLen characters are stored in it. Also, it does not truncate the existing string (use Truncate() for this) even if its current length is greater than nLen .SS wxString& Append (const char* psz) Concatenates psz to this string, returning a reference to it. .SS wxString& Append (char chint count = 1) Concatenates character ch to this string, count times, returning a reference to it. .SS wxString AfterFirst (char ch) Gets all the characters after the first occurrence of ch . Returns the empty string if ch is not found. .SS wxString AfterLast (char ch) Gets all the characters after the last occurrence of ch . Returns the whole string if ch is not found. .SS wxString BeforeFirst (char ch) Gets all characters before the first occurrence of ch . Returns the whole string if ch is not found. .SS wxString BeforeLast (char ch) Gets all characters before the last occurrence of ch . Returns the empty string if ch is not found. .SS const wxChar * c_str () .SS void Clear () Empties the string and frees memory occupied by it. See also Empty .SS int Cmp (const wxString& s) .SS int Cmp (const char* psz) Case-sensitive 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 CmpNoCase , IsSameAs . .SS int CmpNoCase (const wxString& s) .SS int CmpNoCase (const char* psz) 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 . .SS int CompareTo (const char* pszcaseCompare cmp = exact) Case-sensitive comparison. Returns 0 if equal, 1 if greater or -1 if less. .SS bool Contains (const wxString& str) Returns 1 if target appears anywhere in wxString; else 0. .SS void Empty () Makes the string empty, but doesn't free memory occupied by the string. See also Clear() . .SS int Find (char chbool fromEnd = false) Searches for the given character. Returns the starting index, or -1 if not found. .SS int Find (const char* sz) Searches for the given string. Returns the starting index, or -1 if not found. .SS int First (char c) .SS int First (const char* psz) .SS int First (const wxString& str) Same as Find . .SS const wchar_t* fn_str () .SS const char* fn_str () .SS const wxCharBuffer fn_str () .SS static wxString Format (const wxChar *format...) .SS static wxString FormatV (const wxChar *formatva_list argptr) .SS int Freq (char ch) Returns the number of occurrences of ch in the string. .SS static wxString FromAscii (const char* s) .SS static wxString FromAscii (const char c) Converts the string or character from an ASCII, 7-bit form to the native wxString representation. Most useful when using a Unicode build of wxWidgets. Use wxString constructors if you need to convert from another charset. .SS char GetChar (size_t n) Returns the character at position n (read-only). .SS const wxChar* GetData () wxWidgets compatibility conversion. Returns a constant pointer to the data in the string. .SS char& GetWritableChar (size_t n) Returns a reference to the character at position n . .SS wxChar* GetWriteBuf (size_t len) Returns a writable buffer of at least len bytes. It returns a pointer to a new memory block, and the existing data will not be copied. Call wxString::UngetWriteBuf as soon as possible to put the string back into a reasonable state. .SS size_t Index (char ch) .SS size_t Index (const char* sz) Same as wxString::Find . .SS bool IsAscii () Returns true if the string contains only ASCII characters. .SS bool IsEmpty () Returns true if the string is empty. .SS bool IsNull () Returns true if the string is empty (same as IsEmpty ). .SS bool IsNumber () Returns true if the string is an integer (with possible sign). .SS bool IsSameAs (const char* pszbool caseSensitive = true) Test for string equality, case-sensitive (default) or not. caseSensitive is true by default (case matters). Returns true if strings are equal, false otherwise. See also Cmp , CmpNoCase .SS bool IsSameAs (char cbool caseSensitive = true) Test whether the string is equal to the single character c . 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 character, false otherwise. See also Cmp , CmpNoCase .SS bool IsWord () Returns true if the string is a word. TODO: what's the definition of a word? .SS char Last () Returns the last character. .SS char& Last () Returns a reference to the last character (writable). .SS wxString Left (size_t count) Returns the first count characters of the string. .SS size_t Len () Returns the length of the string. .SS size_t Length () Returns the length of the string (same as Len). .SS wxString Lower () Returns this string converted to the lower case. .SS void LowerCase () Same as MakeLower. .SS wxString& MakeLower () Converts all characters to lower case and returns the result. .SS wxString& MakeUpper () Converts all characters to upper case and returns the result. .SS bool Matches (const char* szMask) Returns true if the string contents matches a mask containing '*' and '?'. .SS const char* mb_str (wxMBConv& conv) .SS const wxCharBuffer mb_str (wxMBConv& conv) .SS wxString Mid (size_t firstsize_t count = wxSTRING_MAXLEN) Returns a substring starting at first , with length count , or the rest of the string if count is the default value. .SS wxString& Pad (size_t countchar pad = 'bool fromRight = true) Adds count copies of pad to the beginning, or to the end of the string (the default). Removes spaces from the left or from the right (default). .SS wxString& Prepend (const wxString& str) Prepends str to this string, returning a reference to this string. .SS int Printf (const char* pszFormat...) Similar to the standard function sprintf() . Returns the number of characters written, or an integer less than zero on error. NB: This function will use a safe version of vsprintf() (usually called vsnprintf() ) whenever available to always allocate the buffer of correct size. Unfortunately, this function is not available on all platforms and the dangerous vsprintf() will be used then which may lead to buffer overflows. .SS int PrintfV (const char* pszFormatva_list argPtr) Similar to vprintf. Returns the number of characters written, or an integer less than zero on error. .SS wxString& Remove (size_t pos) Same as Truncate. Removes the portion from pos to the end of the string. .SS wxString& Remove (size_t possize_t len) Removes len characters from the string, starting at pos . .SS wxString& RemoveLast () Removes the last character. .SS size_t Replace (const char* szOldconst char* szNewbool replaceAll = true) Replace first (or all) occurrences of substring with another one. replaceAll : global replace (default), or only the first occurrence. Returns the number of replacements made. .SS wxString Right (size_t count) Returns the last count characters. .SS void SetChar (size_t ncharch) Sets the character at position n . .SS void Shrink () Minimizes the string's memory. This can be useful after a call to Alloc() if too much memory were preallocated. .SS void sprintf (const char* fmt) The same as Printf. .SS bool StartsWith (const wxChar *prefixwxString *rest = NULL) 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 . .SS wxString Strip (stripType s = trailing) Strip characters at the front and/or end. The same as Trim except that it doesn't change this string. .SS wxString SubString (size_t fromsize_t to) Deprecated, use Mid instead (but note that parameters have different meaning). Returns the part of the string between the indices from and to inclusive. .SS const char* ToAscii () Converts the string to an ASCII, 7-bit string (ANSI builds only). .SS const wxCharBuffer ToAscii () Converts the string to an ASCII, 7-bit string in the form of a wxCharBuffer (Unicode builds only). Note that this conversion only works if the string contains only ASCII characters. The mb_str method provides more powerful means of converting wxString to C string. .SS bool ToDouble (double *val) Attempts to convert the string to a floating point number. Returns true on success (the number is stored in the location pointed to by val ) or false if the string does not represent such number. .SS bool ToLong (long *valint base = 10) 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 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. .SS bool ToULong (unsigned long *valint base = 10) 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. 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 wxString::ToLong for the more detailed description of the base parameter. .SS wxString& Trim (bool fromRight = true) Removes spaces from the left or from the right (default). .SS wxString& Truncate (size_t len) Truncate the string to the given length. .SS void UngetWriteBuf () .SS void UngetWriteBuf (size_t len) Puts the string back into a reasonable state (in which it can be used normally), after wxString::GetWriteBuf was called. The version of the function without the len parameter will calculate the new string length itself assuming that the string is terminated by the first NUL character in it while the second one will use the specified length and thus is the only version which should be used with the strings with embedded NUL s (it is also slightly more efficient as strlen() doesn't have to be called). .SS wxString Upper () Returns this string converted to upper case. .SS void UpperCase () The same as MakeUpper. .SS const wchar_t* wc_str (wxMBConv& conv) .SS const wxWCharBuffer wc_str (wxMBConv& conv) .SS bool operator! () Empty string is false, so !string will only return true if the string is empty. This allows the tests for NULLness of a const char * pointer and emptiness of the string to look the same in the code and makes it easier to port old code to wxString. See also IsEmpty() . .SS wxString& operator = (const wxString& str) .SS wxString& operator = (const char* psz) .SS wxString& operator = (char c) .SS wxString& operator = (const unsigned char* psz) .SS wxString& operator = (const wchar_t* pwz) Assignment: the effect of each operation is the same as for the corresponding constructor (see wxString constructors ). .SS wxString operator + (const wxString& xconst wxString& y) .SS wxString operator + (const wxString& xconst char* y) .SS wxString operator + (const wxString& xchar y) .SS wxString operator + (const char* xconst wxString& y) .SS void operator += (const wxString& str) .SS void operator += (const char* psz) .SS void operator += (char c) Concatenation in place: the argument is appended to the string. .SS wxChar& operator [] (size_t i) .SS wxChar operator [] (size_t i) .SS wxChar& operator [] (int i) .SS wxChar operator [] (int i) Element extraction. .SS wxString operator () (size_t startsize_t len) Same as Mid (substring extraction). .SS wxString& operator \cinsert (const wxString& str) .SS wxString& operator \cinsert (const char* psz) .SS wxString& operator \cinsert (char ch) Same as +=. .SS wxString& operator \cinsert (int i) .SS wxString& operator \cinsert (float f) .SS wxString& operator \cinsert (double d) These functions work as C++ stream insertion operators: they insert the given value into the string. Precision or format cannot be set using them, you can use Printf for this. .SS friend istream& operator \cextract (istream& iswxString& str) Extraction from a stream. .SS operator const char* () Implicit conversion to a C string. .SS bool operator == (const wxString& xconst wxString& y) .SS bool operator == (const wxString& xconst char* t) .SS bool operator != (const wxString& xconst wxString& y) .SS bool operator != (const wxString& xconst char* t) .SS bool operator > (const wxString& xconst wxString& y) .SS bool operator > (const wxString& xconst char* t) .SS bool operator >= (const wxString& xconst wxString& y) .SS bool operator >= (const wxString& xconst char* t) .SS bool operator < (const wxString& xconst wxString& y) .SS bool operator < (const wxString& xconst char* t) .SS bool operator <= (const wxString& xconst wxString& y) .SS bool operator <= (const wxString& xconst char* t) .SH "SEE ALSO" Overview .SH "AUTHORS" Documentation content by Julian Smart, Robert Roebling, Vadim Zeitlin, Robin Dunn, et al Conversion to manpage format by Arnout Engelen (http://bzzt.net), bugreports welcome.