1 \section{\class{wxString
}}\label{wxstring
}
3 wxString is a class representing a character string. Please see the
4 \helpref{wxString overview
}{wxstringoverview
} for more information about it.
6 As explained there, wxString implements most of the methods of the std::string
8 These standard functions are not documented in this manual, please see the
9 \urlref{STL documentation
}{http://www.cppreference.com/cppstl.html
}).
10 The behaviour of all these functions is identical to the behaviour described
13 You may notice that wxString sometimes has many functions which do the same
14 thing like, for example,
\helpref{Length()
}{wxstringlength
},
15 \helpref{Len()
}{wxstringlen
} and
{\tt length()
} which all return the string
16 length. In all cases of such duplication the
{\tt std::string
}-compatible
17 method (
{\tt length()
} in this case, always the lowercase version) should be
18 used as it will ensure smoother transition to
{\tt std::string
} when wxWidgets
19 starts using it instead of wxString.
21 \wxheading{Derived from
}
25 \wxheading{Include files
}
31 \helpref{wxBase
}{librarieslist
}
33 \wxheading{Predefined objects
}
41 \helpref{wxString overview
}{wxstringoverview
},
\helpref{Unicode overview
}{unicode
}
43 \latexignore{\rtfignore{\wxheading{Function groups
}}}
46 \membersection{Constructors and assignment operators
}\label{constructorsinwxstring
}
48 A string may be constructed either from a C string, (some number of copies of)
49 a single character or a wide (UNICODE) string. For all constructors (except the
50 default which creates an empty string) there is also a corresponding assignment
53 \helpref{wxString
}{wxstringconstruct
}\\
54 \helpref{operator $=$
}{wxstringoperatorassign
}\\
55 \helpref{\destruct{wxString
}}{wxstringdestruct
}
58 \membersection{String length
}\label{lengthfunctionsinwxstring
}
60 These functions return the string length and check whether the string is empty
63 \helpref{Len
}{wxstringlen
}\\
64 \helpref{IsEmpty
}{wxstringisempty
}\\
65 \helpref{operator!
}{wxstringoperatornot
}\\
66 \helpref{Empty
}{wxstringempty
}\\
67 \helpref{Clear
}{wxstringclear
}
70 \membersection{Character access
}\label{characteraccessinwxstring
}
72 Many functions in this section take a character index in the string. As with C
73 strings and/or arrays, the indices start from $
0$, so the first character of a
74 string is string
[$
0$
]. Attempt to access a character beyond the end of the
75 string (which may be even $
0$ if the string is empty) will provoke an assert
76 failure in
\helpref{debug build
}{debuggingoverview
}, but no checks are done in
79 This section also contains both implicit and explicit conversions to C style
80 strings. Although implicit conversion is quite convenient, it is advised to use
81 explicit
\helpref{c
\_str()
}{wxstringcstr
} method for the sake of clarity. Also
82 see
\helpref{overview
}{wxstringadvices
} for the cases where it is necessary to
85 \helpref{GetChar
}{wxstringgetchar
}\\
86 \helpref{GetWritableChar
}{wxstringgetwritablechar
}\\
87 \helpref{SetChar
}{wxstringsetchar
}\\
88 \helpref{Last
}{wxstringlast
}\\
89 \helpref{operator
[]}{wxstringoperatorbracket
}\\
90 \helpref{c
\_str}{wxstringcstr
}\\
91 \helpref{mb
\_str}{wxstringmbstr
}\\
92 \helpref{wc
\_str}{wxstringwcstr
}\\
93 \helpref{fn
\_str}{wxstringfnstr
}\\
94 \helpref{operator const char*
}{wxstringoperatorconstcharpt
}
97 \membersection{Concatenation
}\label{concatenationinwxstring
}
99 Anything may be concatenated (appended to) with a string. However, you can't
100 append something to a C string (including literal constants), so to do this it
101 should be converted to a wxString first.
103 \helpref{operator
\cinsert}{wxstringoperatorout
}\\
104 \helpref{operator $+=$
}{wxstringplusequal
}\\
105 \helpref{operator $+$
}{wxstringoperatorplus
}\\
106 \helpref{Append
}{wxstringappend
}\\
107 \helpref{Prepend
}{wxstringprepend
}
110 \membersection{Comparison
}\label{comparisoninwxstring
}
112 The default comparison function
\helpref{Cmp
}{wxstringcmp
} is case-sensitive and
113 so is the default version of
\helpref{IsSameAs
}{wxstringissameas
}. For case
114 insensitive comparisons you should use
\helpref{CmpNoCase
}{wxstringcmpnocase
} or
115 give a second parameter to IsSameAs. This last function is may be more
116 convenient if only equality of the strings matters because it returns a boolean
117 \true value if the strings are the same and not
0 (which is usually false in C)
120 \helpref{Matches
}{wxstringmatches
} is a poor man's regular expression matcher:
121 it only understands '*' and '?' metacharacters in the sense of DOS command line
124 \helpref{StartsWith
}{wxstringstartswith
} is helpful when parsing a line of
125 text which should start with some predefined prefix and is more efficient than
126 doing direct string comparison as you would also have to precalculate the
127 length of the prefix then.
129 \helpref{Cmp
}{wxstringcmp
}\\
130 \helpref{CmpNoCase
}{wxstringcmpnocase
}\\
131 \helpref{IsSameAs
}{wxstringissameas
}\\
132 \helpref{Matches
}{wxstringmatches
}\\
133 \helpref{StartsWith
}{wxstringstartswith
}\\
134 \helpref{EndsWith
}{wxstringendswith
}
137 \membersection{Substring extraction
}\label{substringextractioninwxstring
}
139 These functions allow to extract substring from this string. All of them don't
140 modify the original string and return a new string containing the extracted
143 \helpref{Mid
}{wxstringmid
}\\
144 \helpref{operator()
}{wxstringoperatorparenth
}\\
145 \helpref{Left
}{wxstringleft
}\\
146 \helpref{Right
}{wxstringright
}\\
147 \helpref{BeforeFirst
}{wxstringbeforefirst
}\\
148 \helpref{BeforeLast
}{wxstringbeforelast
}\\
149 \helpref{AfterFirst
}{wxstringafterfirst
}\\
150 \helpref{AfterLast
}{wxstringafterlast
}\\
151 \helpref{StartsWith
}{wxstringstartswith
}\\
152 \helpref{EndsWith
}{wxstringendswith
}
156 \membersection{Case conversion
}\label{caseconversioninwxstring
}
158 The MakeXXX() variants modify the string in place, while the other functions
159 return a new string which contains the original text converted to the upper or
160 lower case and leave the original string unchanged.
162 \helpref{MakeUpper
}{wxstringmakeupper
}\\
163 \helpref{Upper
}{wxstringupper
}\\
164 \helpref{MakeLower
}{wxstringmakelower
}\\
165 \helpref{Lower
}{wxstringlower
}
168 \membersection{Searching and replacing
}\label{searchingandreplacinginwxstring
}
170 These functions replace the standard
{\it strchr()
} and
{\it strstr()
}
173 \helpref{Find
}{wxstringfind
}\\
174 \helpref{Replace
}{wxstringreplace
}
177 \membersection{Conversion to numbers
}\label{conversiontonumbersinwxstring
}
179 The string provides functions for conversion to signed and unsigned integer and
180 floating point numbers. All three functions take a pointer to the variable to
181 put the numeric value in and return
\true if the
{\bf entire
} string could be
182 converted to a number.
184 \helpref{ToLong
}{wxstringtolong
}\\
185 \helpref{ToLongLong
}{wxstringtolonglong
}\\
186 \helpref{ToULong
}{wxstringtoulong
}\\
187 \helpref{ToULongLong
}{wxstringtoulonglong
}\\
188 \helpref{ToDouble
}{wxstringtodouble
}
191 \membersection{Writing values into the string
}\label{writingintostringinwxstring
}
193 Both formatted versions (
\helpref{Printf
}{wxstringprintf
}) and stream-like
194 insertion operators exist (for basic types only). Additionally, the
195 \helpref{Format
}{wxstringformat
} function allows to use simply append
196 formatted value to a string:
199 // the following
2 snippets are equivalent
202 s += wxString::Format("
%d", n);
205 s.Printf("...
%d", n);
208 \helpref{Format
}{wxstringformat
}\\
209 \helpref{FormatV
}{wxstringformatv
}\\
210 \helpref{Printf
}{wxstringprintf
}\\
211 \helpref{PrintfV
}{wxstringprintfv
}\\
212 \helpref{operator
\cinsert}{wxstringoperatorout
}
215 \membersection{Memory management
}\label{memoryinwxstring
}
217 These are "advanced" functions and they will be needed quite rarely.
218 \helpref{Alloc
}{wxstringalloc
} and
\helpref{Shrink
}{wxstringshrink
} are only
219 interesting for optimization purposes.
220 \helpref{wxStringBuffer
}{wxstringbuffer
}
221 and
\helpref{wxStringBufferLength
}{wxstringbufferlength
} classes may be very
222 useful when working with some external API which requires the caller to provide
225 \helpref{Alloc
}{wxstringalloc
}\\
226 \helpref{Shrink
}{wxstringshrink
}\\
227 \helpref{wxStringBuffer
}{wxstringbuffer
}\\
228 \helpref{wxStringBufferLength
}{wxstringbufferlength
}
231 \membersection{Miscellaneous
}\label{miscellaneousinwxstring
}
233 Other string functions.
235 \helpref{Trim
}{wxstringtrim
}\\
236 \helpref{Truncate
}{wxstringtruncate
}\\
237 \helpref{Pad
}{wxstringpad
}
240 \membersection{wxWidgets
1.xx compatibility functions
}\label{backwardcompatibilityinwxstring
}
242 These functions are deprecated, please consider using new wxWidgets
2.0
243 functions instead of them (or, even better, std::string compatible variants).
245 % keep ordered alphabetically
246 \helpref{CompareTo
}{wxstringcompareto
}\\
247 \helpref{Contains
}{wxstringcontains
}\\
248 \helpref{First
}{wxstringfirst
}\\
249 \helpref{Freq
}{wxstringfreq
}\\
250 \helpref{Index
}{wxstringindex
}\\
251 \helpref{IsAscii
}{wxstringisascii
}\\
252 \helpref{IsNull
}{wxstringisnull
}\\
253 \helpref{IsNumber
}{wxstringisnumber
}\\
254 \helpref{IsWord
}{wxstringisword
}\\
255 \helpref{Last
}{wxstringlast
}\\
256 \helpref{Length
}{wxstringlength
}\\
257 \helpref{LowerCase
}{wxstringlowercase
}\\
258 \helpref{Remove
}{wxstringremove
}\\
259 \helpref{Strip
}{wxstringstrip
}\\
260 \helpref{SubString
}{wxstringsubstring
}\\
261 \helpref{UpperCase
}{wxstringuppercase
}
264 \membersection{std::string compatibility functions
}\label{wxstringat
}
266 The supported functions are only listed here, please see any STL reference for
270 // take nLen chars starting at nPos
271 wxString(const wxString& str, size_t nPos, size_t nLen);
272 // take all characters from pStart to pEnd (poor man's iterators)
273 wxString(const void *pStart, const void *pEnd);
275 // lib.string.capacity
276 // return the length of the string
278 // return the length of the string
279 size_t length() const;
280 // return the maximum size of the string
281 size_t max_size() const;
282 // resize the string, filling the space with c if c !=
0
283 void resize(size_t nSize, char ch = '
\0');
284 // delete the contents of the string
286 // returns true if the string is empty
290 // return the character at position n
291 char at(size_t n) const;
292 // returns the writable character at position n
295 // lib.string.modifiers
297 wxString& append(const wxString& str);
298 // append elements str
[pos
], ..., str
[pos+n
]
299 wxString& append(const wxString& str, size_t pos, size_t n);
300 // append first n (or all if n == npos) characters of sz
301 wxString& append(const char *sz, size_t n = npos);
303 // append n copies of ch
304 wxString& append(size_t n, char ch);
306 // same as `this_string = str'
307 wxString& assign(const wxString& str);
308 // same as ` = str
[pos..pos + n
]
309 wxString& assign(const wxString& str, size_t pos, size_t n);
310 // same as `= first n (or all if n == npos) characters of sz'
311 wxString& assign(const char *sz, size_t n = npos);
312 // same as `= n copies of ch'
313 wxString& assign(size_t n, char ch);
315 // insert another string
316 wxString& insert(size_t nPos, const wxString& str);
317 // insert n chars of str starting at nStart (in str)
318 wxString& insert(size_t nPos, const wxString& str, size_t nStart, size_t n);
320 // insert first n (or all if n == npos) characters of sz
321 wxString& insert(size_t nPos, const char *sz, size_t n = npos);
322 // insert n copies of ch
323 wxString& insert(size_t nPos, size_t n, char ch);
325 // delete characters from nStart to nStart + nLen
326 wxString& erase(size_t nStart =
0, size_t nLen = npos);
328 // replaces the substring of length nLen starting at nStart
329 wxString& replace(size_t nStart, size_t nLen, const char* sz);
330 // replaces the substring with nCount copies of ch
331 wxString& replace(size_t nStart, size_t nLen, size_t nCount, char ch);
332 // replaces a substring with another substring
333 wxString& replace(size_t nStart, size_t nLen,
334 const wxString& str, size_t nStart2, size_t nLen2);
335 // replaces the substring with first nCount chars of sz
336 wxString& replace(size_t nStart, size_t nLen,
337 const char* sz, size_t nCount);
340 void swap(wxString& str);
342 // All find() functions take the nStart argument which specifies the
343 // position to start the search on, the default value is
0. All functions
344 // return npos if there were no match.
347 size_t find(const wxString& str, size_t nStart =
0) const;
349 // find first n characters of sz
350 size_t find(const char* sz, size_t nStart =
0, size_t n = npos) const;
352 // find the first occurrence of character ch after nStart
353 size_t find(char ch, size_t nStart =
0) const;
355 // rfind() family is exactly like find() but works right to left
357 // as find, but from the end
358 size_t rfind(const wxString& str, size_t nStart = npos) const;
360 // as find, but from the end
361 size_t rfind(const char* sz, size_t nStart = npos,
362 size_t n = npos) const;
363 // as find, but from the end
364 size_t rfind(char ch, size_t nStart = npos) const;
366 // find first/last occurrence of any character in the set
369 size_t find_first_of(const wxString& str, size_t nStart =
0) const;
371 size_t find_first_of(const char* sz, size_t nStart =
0) const;
372 // same as find(char, size_t)
373 size_t find_first_of(char c, size_t nStart =
0) const;
375 size_t find_last_of (const wxString& str, size_t nStart = npos) const;
377 size_t find_last_of (const char* s, size_t nStart = npos) const;
378 // same as rfind(char, size_t)
379 size_t find_last_of (char c, size_t nStart = npos) const;
381 // find first/last occurrence of any character not in the set
384 size_t find_first_not_of(const wxString& str, size_t nStart =
0) const;
386 size_t find_first_not_of(const char* s, size_t nStart =
0) const;
388 size_t find_first_not_of(char ch, size_t nStart =
0) const;
390 size_t find_last_not_of(const wxString& str, size_t nStart=npos) const;
392 size_t find_last_not_of(const char* s, size_t nStart = npos) const;
394 size_t find_last_not_of(char ch, size_t nStart = npos) const;
396 // All compare functions return a negative, zero or positive value
397 // if the
[sub
]string is less, equal or greater than the compare() argument.
399 // just like strcmp()
400 int compare(const wxString& str) const;
401 // comparison with a substring
402 int compare(size_t nStart, size_t nLen, const wxString& str) const;
403 // comparison of
2 substrings
404 int compare(size_t nStart, size_t nLen,
405 const wxString& str, size_t nStart2, size_t nLen2) const;
406 // just like strcmp()
407 int compare(const char* sz) const;
408 // substring comparison with first nCount characters of sz
409 int compare(size_t nStart, size_t nLen,
410 const char* sz, size_t nCount = npos) const;
412 // substring extraction
413 wxString substr(size_t nStart =
0, size_t nLen = npos) const;
416 %%%%% MEMBERS HERE %%%%%
417 \helponly{\insertatlevel{2}{
424 \membersection{wxString::wxString
}\label{wxstringconstruct
}
426 \func{}{wxString
}{\void}
428 Default constructor. Initializes the string to
{\tt ""
} (empty string).
430 \func{}{wxString
}{\param{const wxString\&
}{ x
}}
434 \func{}{wxString
}{\param{wxChar
}{ ch
},
\param{size
\_t}{ n =
1}}
436 Constructs a string of
{\it n
} copies of character
{\it ch
}.
438 \func{}{wxString
}{\param{const wxChar*
}{ psz
},
\param{size
\_t}{ nLength = wxSTRING
\_MAXLEN}}
440 Takes first
{\it nLength
} characters from the C string
{\it psz
}.
441 The default value of
{\tt wxSTRING
\_MAXLEN} means to take all the string.
443 Note that this constructor may be used even if
{\it psz
} points to a buffer
444 with binary data (i.e. containing
{\tt NUL
} characters) as long as you provide
445 the correct value for
{\it nLength
}. However, the default form of it works
446 only with strings without intermediate
{\tt NUL
}s because it uses
447 {\tt strlen()
} to calculate the effective length and it would not give correct
450 \func{}{wxString
}{\param{const unsigned char*
}{ psz
},
\param{size
\_t}{ nLength = wxSTRING
\_MAXLEN}}
452 For compilers using unsigned char: takes first
{\it nLength
} characters from the C string
{\it psz
}.
453 The default value of
{\tt wxSTRING
\_MAXLEN} means take all the string.
454 For ANSI builds only (note the use of
{\tt char
} instead of
{\tt wxChar
}).
456 \wxheading{Constructors with conversion
}
458 The following constructors allow you to construct wxString from a wide string
459 in ANSI build or from a C string in Unicode build.
461 \func{}{wxString
}{\param{const wchar
\_t*
}{ psz
},
\param{const wxMBConv\&
}{ conv
},
\param{size
\_t}{ nLength = wxSTRING
\_MAXLEN}}
463 Initializes the string from first
\arg{nLength
} characters of wide string.
464 The default value of
{\tt wxSTRING
\_MAXLEN} means take all the string.
465 In ANSI build,
\arg{conv
}'s
466 \helpref{WC2MB
}{wxmbconvwc2mb
} method is called to
467 convert
\arg{psz
} to wide string. It is ignored in Unicode build.
469 \func{}{wxString
}{\param{const char*
}{ psz
},
\param{const wxMBConv\&
}{ conv = wxConvLibc
},
\param{size
\_t}{ nLength = wxSTRING
\_MAXLEN}}
471 Initializes the string from first
\arg{nLength
} characters of C string.
472 The default value of
{\tt wxSTRING
\_MAXLEN} means take all the string.
473 In Unicode build,
\arg{conv
}'s
474 \helpref{MB2WC
}{wxmbconvmb2wc
} method is called to
475 convert
\arg{psz
} to wide string (the default converter uses current locale's
476 charset). It is ignored in ANSI build.
480 \helpref{wxMBConv classes
}{mbconvclasses
},
\helpref{mb
\_str}{wxstringmbstr
},
481 \helpref{wc
\_str}{wxstringwcstr
}
484 \membersection{wxString::
\destruct{wxString
}}\label{wxstringdestruct
}
486 \func{}{\destruct{wxString
}}{\void}
488 String destructor. Note that this is not virtual, so wxString must not be inherited from.
491 \membersection{wxString::Alloc
}\label{wxstringalloc
}
493 \func{void
}{Alloc
}{\param{size
\_t}{ nLen
}}
495 Preallocate enough space for wxString to store
{\it nLen
} characters. This function
496 may be used to increase speed when the string is constructed by repeated
501 // delete all vowels from the string
502 wxString DeleteAllVowels(const wxString& original)
506 size_t len = original.length();
510 for ( size_t n =
0; n < len; n++ )
512 if ( strchr("aeuio", tolower(original
[n
])) == NULL )
513 result += original
[n
];
521 because it will avoid the need to reallocate string memory many times (in case
522 of long strings). Note that it does not set the maximal length of a string - it
523 will still expand if more than
{\it nLen
} characters are stored in it. Also, it
524 does not truncate the existing string (use
525 \helpref{Truncate()
}{wxstringtruncate
} for this) even if its current length is
526 greater than
{\it nLen
}
529 \membersection{wxString::Append
}\label{wxstringappend
}
531 \func{wxString\&
}{Append
}{\param{const wxChar*
}{ psz
}}
533 Concatenates
{\it psz
} to this string, returning a reference to it.
535 \func{wxString\&
}{Append
}{\param{wxChar
}{ ch
},
\param{int
}{ count =
1}}
537 Concatenates character
{\it ch
} to this string,
{\it count
} times, returning a reference
541 \membersection{wxString::AfterFirst
}\label{wxstringafterfirst
}
543 \constfunc{wxString
}{AfterFirst
}{\param{wxChar
}{ ch
}}
545 Gets all the characters after the first occurrence of
{\it ch
}.
546 Returns the empty string if
{\it ch
} is not found.
549 \membersection{wxString::AfterLast
}\label{wxstringafterlast
}
551 \constfunc{wxString
}{AfterLast
}{\param{wxChar
}{ ch
}}
553 Gets all the characters after the last occurrence of
{\it ch
}.
554 Returns the whole string if
{\it ch
} is not found.
557 \membersection{wxString::BeforeFirst
}\label{wxstringbeforefirst
}
559 \constfunc{wxString
}{BeforeFirst
}{\param{wxChar
}{ ch
}}
561 Gets all characters before the first occurrence of
{\it ch
}.
562 Returns the whole string if
{\it ch
} is not found.
565 \membersection{wxString::BeforeLast
}\label{wxstringbeforelast
}
567 \constfunc{wxString
}{BeforeLast
}{\param{wxChar
}{ ch
}}
569 Gets all characters before the last occurrence of
{\it ch
}.
570 Returns the empty string if
{\it ch
} is not found.
573 \membersection{wxString::c
\_str}\label{wxstringcstr
}
575 \constfunc{const wxChar *
}{c
\_str}{\void}
577 Returns a pointer to the string data (
{\tt const char*
} in ANSI build,
578 {\tt const wchar
\_t*
} in Unicode build).
580 Note that the returned value is not convertible to
{\tt char*
} or
581 {\tt wchar
\_t*
}, use
\helpref{char
\_str}{wxstringcharstr
} or
582 \helpref{wchar
\_string}{wxstringwcharstr
} if you need to pass string value
583 to a function expecting non-const pointer.
587 \helpref{mb
\_str}{wxstringmbstr
},
\helpref{wc
\_str}{wxstringwcstr
},
588 \helpref{fn
\_str}{wxstringfnstr
},
\helpref{char
\_str}{wxstringcharstr
},
589 \helpref{wchar
\_string}{wxstringwcharstr
}
591 \membersection{wxString::char
\_str}\label{wxstringcharstr
}
593 \constfunc{wxWritableCharBuffer
}{char
\_str}{\param{const wxMBConv\&
}{ conv = wxConvLibc
}}
595 Returns an object with string data that is implicitly convertible to
596 {\tt char*
} pointer. Note that any change to the returned buffer is lost and so
597 this function is only usable for passing strings to legacy libraries that
598 don't have const-correct API. Use
\helpref{wxStringBuffer
}{wxstringbuffer
} if
599 you want to modify the string.
603 \helpref{mb
\_str}{wxstringmbstr
},
\helpref{wc
\_str}{wxstringwcstr
},
604 \helpref{fn
\_str}{wxstringfnstr
},
\helpref{c
\_str}{wxstringcstr
},
605 \helpref{wchar
\_str}{wxstringwcharstr
}
608 \membersection{wxString::Clear
}\label{wxstringclear
}
610 \func{void
}{Clear
}{\void}
612 Empties the string and frees memory occupied by it.
614 See also:
\helpref{Empty
}{wxstringempty
}
617 \membersection{wxString::Cmp
}\label{wxstringcmp
}
619 \constfunc{int
}{Cmp
}{\param{const wxString\&
}{ s
}}
621 \constfunc{int
}{Cmp
}{\param{const wxChar*
}{ psz
}}
623 Case-sensitive comparison.
625 Returns a positive value if the string is greater than the argument, zero if
626 it is equal to it or a negative value if it is less than the argument (same semantics
627 as the standard
{\it strcmp()
} function).
629 See also
\helpref{CmpNoCase
}{wxstringcmpnocase
},
\helpref{IsSameAs
}{wxstringissameas
}.
632 \membersection{wxString::CmpNoCase
}\label{wxstringcmpnocase
}
634 \constfunc{int
}{CmpNoCase
}{\param{const wxString\&
}{ s
}}
636 \constfunc{int
}{CmpNoCase
}{\param{const wxChar*
}{ psz
}}
638 Case-insensitive comparison.
640 Returns a positive value if the string is greater than the argument, zero if
641 it is equal to it or a negative value if it is less than the argument (same semantics
642 as the standard
{\it strcmp()
} function).
644 See also
\helpref{Cmp
}{wxstringcmp
},
\helpref{IsSameAs
}{wxstringissameas
}.
647 \membersection{wxString::CompareTo
}\label{wxstringcompareto
}
650 enum wxString::caseCompare
{exact, ignoreCase
};
653 \constfunc{int
}{CompareTo
}{\param{const wxChar*
}{ psz
},
\param{caseCompare
}{ cmp = exact
}}
655 Case-sensitive comparison. Returns
0 if equal,
1 if greater or -
1 if less.
657 This is a wxWidgets
1.xx compatibility function; use
\helpref{Cmp
}{wxstringcmp
} instead.
660 \membersection{wxString::Contains
}\label{wxstringcontains
}
662 \constfunc{bool
}{Contains
}{\param{const wxString\&
}{ str
}}
664 Returns
\true if target appears anywhere in wxString; else
\false.
666 This is a wxWidgets
1.xx compatibility function; you should not use it in new code.
669 \membersection{wxString::Empty
}\label{wxstringempty
}
671 \func{void
}{Empty
}{\void}
673 Makes the string empty, but doesn't free memory occupied by the string.
675 See also:
\helpref{Clear()
}{wxstringclear
}.
678 \membersection{wxString::Find
}\label{wxstringfind
}
680 \constfunc{int
}{Find
}{\param{wxUniChar
}{ ch
},
\param{bool
}{ fromEnd = false
}}
682 Searches for the given character. Returns the starting index, or
{\tt wxNOT
\_FOUND} if not found.
684 \constfunc{int
}{Find
}{\param{const wxString\&
}{ sub
}}
686 Searches for the given string. Returns the starting index, or
{\tt wxNOT
\_FOUND} if not found.
689 \membersection{wxString::First
}\label{wxstringfirst
}
691 \func{int
}{First
}{\param{wxChar
}{ c
}}
693 \constfunc{int
}{First
}{\param{const wxChar*
}{ psz
}}
695 \constfunc{int
}{First
}{\param{const wxString\&
}{ str
}}
697 Same as
\helpref{Find
}{wxstringfind
}.
699 This is a wxWidgets
1.xx compatibility function; you should not use it in new code.
702 \membersection{wxString::fn
\_str}\label{wxstringfnstr
}
704 \constfunc{const wchar
\_t*
}{fn
\_str}{\void}
706 \constfunc{const char*
}{fn
\_str}{\void}
708 \constfunc{const wxCharBuffer
}{fn
\_str}{\void}
710 Returns string representation suitable for passing to OS' functions for
711 file handling. In ANSI build, this is same as
\helpref{c
\_str}{wxstringcstr
}.
712 In Unicode build, returned value can be either wide character string
713 or C string in charset matching the
{\tt wxConvFileName
} object, depending on
718 \helpref{wxMBConv
}{wxmbconv
},
719 \helpref{wc
\_str}{wxstringwcstr
},
\helpref{mb
\_str}{wxstringwcstr
}
722 \membersection{wxString::Format
}\label{wxstringformat
}
724 \func{static wxString
}{Format
}{\param{const wxChar
}{*format
},
\param{}{...
}}
726 This static function returns the string containing the result of calling
727 \helpref{Printf
}{wxstringprintf
} with the passed parameters on it.
731 \helpref{FormatV
}{wxstringformatv
},
\helpref{Printf
}{wxstringprintf
}
734 \membersection{wxString::FormatV
}\label{wxstringformatv
}
736 \func{static wxString
}{FormatV
}{\param{const wxChar
}{*format
},
\param{va
\_list }{argptr
}}
738 This static function returns the string containing the result of calling
739 \helpref{PrintfV
}{wxstringprintfv
} with the passed parameters on it.
743 \helpref{Format
}{wxstringformat
},
\helpref{PrintfV
}{wxstringprintfv
}
746 \membersection{wxString::Freq
}\label{wxstringfreq
}
748 \constfunc{int
}{Freq
}{\param{wxChar
}{ch
}}
750 Returns the number of occurrences of
{\it ch
} in the string.
752 This is a wxWidgets
1.xx compatibility function; you should not use it in new code.
754 \membersection{wxString::From8BitData
}\label{wxstringfrom8bitdata
}
756 \func{static wxString
}{From8BitData
}{\param{const char*
}{ buf
},
\param{size
\_t}{len
}}
758 \func{static wxString
}{From8BitData
}{\param{const char*
}{ buf
}}
760 Converts given buffer of binary data from
8-bit string to wxString. In Unicode
761 build, the string is interpreted as being in ISO-
8859-
1 encoding. The version
762 without
\arg{len
} parameter takes NUL-terminated data.
764 This is a convenience method useful when storing binary data in wxString.
770 \helpref{To8BitData
}{wxstringto8bitdata
}
773 \membersection{wxString::FromAscii
}\label{wxstringfromascii
}
775 \func{static wxString
}{FromAscii
}{\param{const char*
}{ s
}}
777 \func{static wxString
}{FromAscii
}{\param{const char*
}{ s
},
\param{size
\_t}{ len
}}
779 \func{static wxString
}{FromAscii
}{\param{const char
}{ c
}}
781 Converts the string or character from an ASCII,
7-bit form
782 to the native wxString representation. Most useful when using
783 a Unicode build of wxWidgets (note the use of
{\tt char
} instead of
{\tt wxChar
}).
784 Use
\helpref{wxString constructors
}{wxstringconstruct
} if you
785 need to convert from another charset.
788 \membersection{wxString::FromUTF8
}\label{wxstringfromutf8
}
790 \func{static wxString
}{FromUTF8
}{\param{const char*
}{ s
}}
792 \func{static wxString
}{FromUTF8
}{\param{const char*
}{ s
},
\param{size
\_t}{ len
}}
794 Converts C string encoded in UTF-
8 to wxString.
796 Note that this method assumes that
\arg{s
} is a valid UTF-
8 sequence and
797 doesn't do any validation in release builds, it's validity is only checked in
801 \membersection{wxString::GetChar
}\label{wxstringgetchar
}
803 \constfunc{wxChar
}{GetChar
}{\param{size
\_t}{ n
}}
805 Returns the character at position
{\it n
} (read-only).
808 \membersection{wxString::GetData
}\label{wxstringgetdata
}
810 \constfunc{const wxChar*
}{GetData
}{\void}
812 wxWidgets compatibility conversion. Returns a constant pointer to the data in the string.
815 \membersection{wxString::GetWritableChar
}\label{wxstringgetwritablechar
}
817 \func{wxChar\&
}{GetWritableChar
}{\param{size
\_t}{ n
}}
819 Returns a reference to the character at position
{\it n
}.
822 \membersection{wxString::GetWriteBuf
}\label{wxstringgetwritebuf
}
824 \func{wxChar*
}{GetWriteBuf
}{\param{size
\_t}{ len
}}
826 Returns a writable buffer of at least
{\it len
} bytes.
827 It returns a pointer to a new memory block, and the
828 existing data will not be copied.
830 Call
\helpref{wxString::UngetWriteBuf
}{wxstringungetwritebuf
} as soon as
831 possible to put the string back into a reasonable state.
833 This method is deprecated, please use
834 \helpref{wxStringBuffer
}{wxstringbuffer
} or
835 \helpref{wxStringBufferLength
}{wxstringbufferlength
} instead.
838 \membersection{wxString::Index
}\label{wxstringindex
}
840 \constfunc{size
\_t}{Index
}{\param{wxChar
}{ ch
}}
842 \constfunc{size
\_t}{Index
}{\param{const wxChar*
}{ sz
}}
844 Same as
\helpref{wxString::Find
}{wxstringfind
}.
846 This is a wxWidgets
1.xx compatibility function; you should not use it in new code.
849 \membersection{wxString::IsAscii
}\label{wxstringisascii
}
851 \constfunc{bool
}{IsAscii
}{\void}
853 Returns
\true if the string contains only ASCII characters.
855 This is a wxWidgets
1.xx compatibility function; you should not use it in new code.
858 \membersection{wxString::IsEmpty
}\label{wxstringisempty
}
860 \constfunc{bool
}{IsEmpty
}{\void}
862 Returns
\true if the string is empty.
865 \membersection{wxString::IsNull
}\label{wxstringisnull
}
867 \constfunc{bool
}{IsNull
}{\void}
869 Returns
\true if the string is empty (same as
\helpref{IsEmpty
}{wxstringisempty
}).
871 This is a wxWidgets
1.xx compatibility function; you should not use it in new code.
874 \membersection{wxString::IsNumber
}\label{wxstringisnumber
}
876 \constfunc{bool
}{IsNumber
}{\void}
878 Returns
\true if the string is an integer (with possible sign).
880 This is a wxWidgets
1.xx compatibility function; you should not use it in new code.
883 \membersection{wxString::IsSameAs
}\label{wxstringissameas
}
885 \constfunc{bool
}{IsSameAs
}{\param{const wxChar*
}{ psz
},
\param{bool
}{ caseSensitive = true
}}
887 Test for string equality, case-sensitive (default) or not.
889 caseSensitive is
\true by default (case matters).
891 Returns
\true if strings are equal,
\false otherwise.
893 See also
\helpref{Cmp
}{wxstringcmp
},
\helpref{CmpNoCase
}{wxstringcmpnocase
}
895 \constfunc{bool
}{IsSameAs
}{\param{wxChar
}{ c
},
\param{bool
}{ caseSensitive = true
}}
897 Test whether the string is equal to the single character
{\it c
}. The test is
898 case-sensitive if
{\it caseSensitive
} is
\true (default) or not if it is
\false.
900 Returns
\true if the string is equal to the character,
\false otherwise.
902 See also
\helpref{Cmp
}{wxstringcmp
},
\helpref{CmpNoCase
}{wxstringcmpnocase
}
905 \membersection{wxString::IsWord
}\label{wxstringisword
}
907 \constfunc{bool
}{IsWord
}{\void}
909 Returns
\true if the string is a word.
911 This is a wxWidgets
1.xx compatibility function; you should not use it in new code.
914 \membersection{wxString::Last
}\label{wxstringlast
}
916 \constfunc{wxChar
}{Last
}{\void}
918 Returns the last character.
920 \func{wxChar\&
}{Last
}{\void}
922 Returns a reference to the last character (writable).
924 This is a wxWidgets
1.xx compatibility function; you should not use it in new code.
927 \membersection{wxString::Left
}\label{wxstringleft
}
929 \constfunc{wxString
}{Left
}{\param{size
\_t}{ count
}}
931 Returns the first
{\it count
} characters of the string.
934 \membersection{wxString::Len
}\label{wxstringlen
}
936 \constfunc{size
\_t}{Len
}{\void}
938 Returns the length of the string.
941 \membersection{wxString::Length
}\label{wxstringlength
}
943 \constfunc{size
\_t}{Length
}{\void}
945 Returns the length of the string (same as Len).
947 This is a wxWidgets
1.xx compatibility function; you should not use it in new code.
950 \membersection{wxString::Lower
}\label{wxstringlower
}
952 \constfunc{wxString
}{Lower
}{\void}
954 Returns this string converted to the lower case.
957 \membersection{wxString::LowerCase
}\label{wxstringlowercase
}
959 \func{void
}{LowerCase
}{\void}
963 This is a wxWidgets
1.xx compatibility function; you should not use it in new code.
966 \membersection{wxString::MakeLower
}\label{wxstringmakelower
}
968 \func{wxString\&
}{MakeLower
}{\void}
970 Converts all characters to lower case and returns the result.
973 \membersection{wxString::MakeUpper
}\label{wxstringmakeupper
}
975 \func{wxString\&
}{MakeUpper
}{\void}
977 Converts all characters to upper case and returns the result.
980 \membersection{wxString::Matches
}\label{wxstringmatches
}
982 \constfunc{bool
}{Matches
}{\param{const wxString\&
}{ mask
}}
984 Returns
\true if the string contents matches a mask containing '*' and '?'.
987 \membersection{wxString::mb
\_str}\label{wxstringmbstr
}
989 \constfunc{const char*
}{mb
\_str}{\param{const wxMBConv\&
}{ conv = wxConvLibc
}}
991 \constfunc{const wxCharBuffer
}{mb
\_str}{\param{const wxMBConv\&
}{ conv = wxConvLibc
}}
993 Returns multibyte (C string) representation of the string.
994 In Unicode build, converts using
\arg{conv
}'s
\helpref{cWC2MB
}{wxmbconvcwc2mb
}
995 method and returns wxCharBuffer. In ANSI build, this function is same
996 as
\helpref{c
\_str}{wxstringcstr
}.
997 The macro wxWX2MBbuf is defined as the correct return type (without const).
1001 \helpref{wxMBConv
}{wxmbconv
},
1002 \helpref{c
\_str}{wxstringcstr
},
\helpref{wc
\_str}{wxstringwcstr
},
1003 \helpref{fn
\_str}{wxstringfnstr
},
\helpref{char
\_str}{wxstringcharstr
}
1006 \membersection{wxString::Mid
}\label{wxstringmid
}
1008 \constfunc{wxString
}{Mid
}{\param{size
\_t}{ first
},
\param{size
\_t}{ count = wxSTRING
\_MAXLEN}}
1010 Returns a substring starting at
{\it first
}, with length
{\it count
}, or the rest of
1011 the string if
{\it count
} is the default value.
1014 \membersection{wxString::Pad
}\label{wxstringpad
}
1016 \func{wxString\&
}{Pad
}{\param{size
\_t}{ count
},
\param{wxChar
}{ pad = ' '
},
\param{bool
}{ fromRight = true
}}
1018 Adds
{\it count
} copies of
{\it pad
} to the beginning, or to the end of the string (the default).
1020 Removes spaces from the left or from the right (default).
1023 \membersection{wxString::Prepend
}\label{wxstringprepend
}
1025 \func{wxString\&
}{Prepend
}{\param{const wxString\&
}{ str
}}
1027 Prepends
{\it str
} to this string, returning a reference to this string.
1030 \membersection{wxString::Printf
}\label{wxstringprintf
}
1032 \func{int
}{Printf
}{\param{const wxChar*
}{pszFormat
},
\param{}{...
}}
1034 Similar to the standard function
{\it sprintf()
}. Returns the number of
1035 characters written, or an integer less than zero on error.
1037 Note that if
{\tt wxUSE
\_PRINTF\_POS\_PARAMS} is set to
1, then this function supports
1038 Unix98-style positional parameters:
1043 str.Printf(wxT("
%d %d %d"), 1, 2, 3);
1044 // str now contains "
1 2 3"
1046 str.Printf(wxT("
%2$d %3$d %1$d"), 1, 2, 3);
1047 // str now contains "
2 3 1"
1050 {\bf NB:
} This function will use a safe version of
{\it vsprintf()
} (usually called
1051 {\it vsnprintf()
}) whenever available to always allocate the buffer of correct
1052 size. Unfortunately, this function is not available on all platforms and the
1053 dangerous
{\it vsprintf()
} will be used then which may lead to buffer overflows.
1056 \membersection{wxString::PrintfV
}\label{wxstringprintfv
}
1058 \func{int
}{PrintfV
}{\param{const wxChar*
}{pszFormat
},
\param{va
\_list}{ argPtr
}}
1060 Similar to vprintf. Returns the number of characters written, or an integer less than zero
1064 \membersection{wxString::Remove
}\label{wxstringremove
}
1066 \func{wxString\&
}{Remove
}{\param{size
\_t}{ pos
}}
1068 Same as Truncate. Removes the portion from
{\it pos
} to the end of the string.
1070 \func{wxString\&
}{Remove
}{\param{size
\_t}{ pos
},
\param{size
\_t}{ len
}}
1072 Removes
{\it len
} characters from the string, starting at
{\it pos
}.
1074 This is a wxWidgets
1.xx compatibility function; you should not use it in new code.
1077 \membersection{wxString::RemoveLast
}\label{wxstringremovelast
}
1079 \func{wxString\&
}{RemoveLast
}{\void}
1081 Removes the last character.
1084 \membersection{wxString::Replace
}\label{wxstringreplace
}
1086 \func{size
\_t}{Replace
}{\param{const wxString\&
}{ strOld
},
\param{const wxString\&
}{ strNew
},
\param{bool
}{ replaceAll = true
}}
1088 Replace first (or all) occurrences of substring with another one.
1090 {\it replaceAll
}: global replace (default), or only the first occurrence.
1092 Returns the number of replacements made.
1095 \membersection{wxString::Right
}\label{wxstringright
}
1097 \constfunc{wxString
}{Right
}{\param{size
\_t}{ count
}}
1099 Returns the last
{\it count
} characters.
1102 \membersection{wxString::SetChar
}\label{wxstringsetchar
}
1104 \func{void
}{SetChar
}{\param{size
\_t}{ n
},
\param{wxChar
}{ch
}}
1106 Sets the character at position
{\it n
}.
1109 \membersection{wxString::Shrink
}\label{wxstringshrink
}
1111 \func{void
}{Shrink
}{\void}
1113 Minimizes the string's memory. This can be useful after a call to
1114 \helpref{Alloc()
}{wxstringalloc
} if too much memory were preallocated.
1117 \membersection{wxString::StartsWith
}\label{wxstringstartswith
}
1119 \constfunc{bool
}{StartsWith
}{\param{const wxString\&
}{prefix
},
\param{wxString
}{*rest = NULL
}}
1121 This function can be used to test if the string starts with the specified
1122 {\it prefix
}. If it does, the function will return
\true and put the rest
1123 of the string (i.e. after the prefix) into
{\it rest
} string if it is not
1124 {\tt NULL
}. Otherwise, the function returns
\false and doesn't modify the
1128 \membersection{wxString::EndsWith
}\label{wxstringendswith
}
1130 \constfunc{bool
}{EndsWith
}{\param{const wxString\&
}{suffix
},
\param{wxString
}{*rest = NULL
}}
1132 This function can be used to test if the string ends with the specified
1133 {\it suffix
}. If it does, the function will return
\true and put the
1134 beginning of the string before the suffix into
{\it rest
} string if it is not
1135 {\tt NULL
}. Otherwise, the function returns
\false and doesn't
1136 modify the
{\it rest
}.
1139 \membersection{wxString::Strip
}\label{wxstringstrip
}
1142 enum wxString::stripType
{leading =
0x1, trailing =
0x2, both =
0x3};
1145 \constfunc{wxString
}{Strip
}{\param{stripType
}{ s = trailing
}}
1147 Strip characters at the front and/or end. The same as Trim except that it
1148 doesn't change this string.
1150 This is a wxWidgets
1.xx compatibility function; you should not use it in new code.
1153 \membersection{wxString::SubString
}\label{wxstringsubstring
}
1155 \constfunc{wxString
}{SubString
}{\param{size
\_t}{ from
},
\param{size
\_t}{ to
}}
1157 Returns the part of the string between the indices
{\it from
} and
{\it to
}
1160 This is a wxWidgets
1.xx compatibility function, use
\helpref{Mid
}{wxstringmid
}
1161 instead (but note that parameters have different meaning).
1164 \membersection{wxString::To8BitData
}\label{wxstringto8bitdata
}
1166 \constfunc{const char*
}{To8BitData
}{\void}
1168 Converts the string to an
8-bit string (ANSI builds only).
1170 \constfunc{const wxCharBuffer
}{To8BitData
}{\void}
1172 Converts the string to an
8-bit string in ISO-
8859-
1 encoding in the form of
1173 a wxCharBuffer (Unicode builds only).
1175 This is a convenience method useful when storing binary data in wxString.
1179 \wxheading{See also
}
1181 \helpref{From8BitData
}{wxstringfrom8bitdata
}
1184 \membersection{wxString::ToAscii
}\label{wxstringtoascii
}
1186 \constfunc{const char*
}{ToAscii
}{\void}
1188 \constfunc{const wxCharBuffer
}{ToAscii
}{\void}
1190 Converts the string to an ASCII,
7-bit string in the form of
1191 a wxCharBuffer (Unicode builds only) or a C string (ANSI builds).
1193 Note that this conversion only works if the string contains only ASCII
1194 characters. The
\helpref{mb
\_str}{wxstringmbstr
} method provides more
1195 powerful means of converting wxString to C string.
1198 \membersection{wxString::ToDouble
}\label{wxstringtodouble
}
1200 \constfunc{bool
}{ToDouble
}{\param{double
}{ *val
}}
1202 Attempts to convert the string to a floating point number. Returns
\true on
1203 success (the number is stored in the location pointed to by
{\it val
}) or
\false
1204 if the string does not represent such number.
1206 \wxheading{See also
}
1208 \helpref{wxString::ToLong
}{wxstringtolong
},\\
1209 \helpref{wxString::ToULong
}{wxstringtoulong
}
1212 \membersection{wxString::ToLong
}\label{wxstringtolong
}
1214 \constfunc{bool
}{ToLong
}{\param{long
}{ *val
},
\param{int
}{base = $
10$
}}
1216 Attempts to convert the string to a signed integer in base
{\it base
}. Returns
1217 \true on success in which case the number is stored in the location
1218 pointed to by
{\it val
} or
\false if the string does not represent a
1219 valid number in the given base.
1221 The value of
{\it base
} must be comprised between $
2$ and $
36$, inclusive, or
1222 be a special value $
0$ which means that the usual rules of
{\tt C
} numbers are
1223 applied: if the number starts with
{\tt 0x
} it is considered to be in base
1224 $
16$, if it starts with
{\tt 0} - in base $
8$ and in base $
10$ otherwise. Note
1225 that you may not want to specify the base $
0$ if you are parsing the numbers
1226 which may have leading zeroes as they can yield unexpected (to the user not
1227 familiar with C) results.
1229 \wxheading{See also
}
1231 \helpref{wxString::ToDouble
}{wxstringtodouble
},\\
1232 \helpref{wxString::ToULong
}{wxstringtoulong
}
1235 \membersection{wxString::ToLongLong
}\label{wxstringtolonglong
}
1237 \constfunc{bool
}{ToLongLong
}{\param{wxLongLong
\_t}{ *val
},
\param{int
}{base = $
10$
}}
1239 This is exactly the same as
\helpref{ToLong
}{wxstringtolong
} but works with
64
1240 bit integer numbers.
1242 Notice that currently it doesn't work (always returns
\false) if parsing of
64
1243 bit numbers is not supported by the underlying C run-time library. Compilers
1244 with C99 support and Microsoft Visual C++ version
7 and higher do support this.
1246 \wxheading{See also
}
1248 \helpref{wxString::ToLong
}{wxstringtolong
},\\
1249 \helpref{wxString::ToULongLong
}{wxstringtoulonglong
}
1252 \membersection{wxString::ToULong
}\label{wxstringtoulong
}
1254 \constfunc{bool
}{ToULong
}{\param{unsigned long
}{ *val
},
\param{int
}{base = $
10$
}}
1256 Attempts to convert the string to an unsigned integer in base
{\it base
}.
1257 Returns
\true on success in which case the number is stored in the
1258 location pointed to by
{\it val
} or
\false if the string does not
1259 represent a valid number in the given base. Please notice that this function
1260 behaves in the same way as the standard
\texttt{strtoul()
} and so it simply
1261 converts negative numbers to unsigned representation instead of rejecting them
1262 (e.g. $-
1$ is returned as
\texttt{ULONG
\_MAX}).
1264 See
\helpref{wxString::ToLong
}{wxstringtolong
} for the more detailed
1265 description of the
{\it base
} parameter.
1267 \wxheading{See also
}
1269 \helpref{wxString::ToDouble
}{wxstringtodouble
},\\
1270 \helpref{wxString::ToLong
}{wxstringtolong
}
1273 \membersection{wxString::ToULongLong
}\label{wxstringtoulonglong
}
1275 \constfunc{bool
}{ToULongLong
}{\param{wxULongLong
\_t}{ *val
},
\param{int
}{base = $
10$
}}
1277 This is exactly the same as
\helpref{ToULong
}{wxstringtoulong
} but works with
64
1278 bit integer numbers.
1280 Please see
\helpref{ToLongLong
}{wxstringtolonglong
} for additional remarks.
1283 \membersection{wxString::ToUTF8
}\label{wxstringtoutf8
}
1285 \constfunc{const char*
}{ToUTF8
}{\void}
1287 \constfunc{const wxCharBuffer
}{ToUF8
}{\void}
1289 Same as
\helpref{utf8
\_str}{wxstringutf8str
}.
1292 \membersection{wxString::Trim
}\label{wxstringtrim
}
1294 \func{wxString\&
}{Trim
}{\param{bool
}{ fromRight = true
}}
1296 Removes white-space (space, tabs, form feed, newline and carriage return) from
1297 the left or from the right end of the string (right is default).
1300 \membersection{wxString::Truncate
}\label{wxstringtruncate
}
1302 \func{wxString\&
}{Truncate
}{\param{size
\_t}{ len
}}
1304 Truncate the string to the given length.
1307 \membersection{wxString::UngetWriteBuf
}\label{wxstringungetwritebuf
}
1309 \func{void
}{UngetWriteBuf
}{\void}
1311 \func{void
}{UngetWriteBuf
}{\param{size
\_t }{len
}}
1313 Puts the string back into a reasonable state (in which it can be used
1315 \rtfsp\helpref{wxString::GetWriteBuf
}{wxstringgetwritebuf
} was called.
1317 The version of the function without the
{\it len
} parameter will calculate the
1318 new string length itself assuming that the string is terminated by the first
1319 {\tt NUL
} character in it while the second one will use the specified length
1320 and thus is the only version which should be used with the strings with
1321 embedded
{\tt NUL
}s (it is also slightly more efficient as
{\tt strlen()
}
1322 doesn't have to be called).
1324 This method is deprecated, please use
1325 \helpref{wxStringBuffer
}{wxstringbuffer
} or
1326 \helpref{wxStringBufferLength
}{wxstringbufferlength
} instead.
1329 \membersection{wxString::Upper
}\label{wxstringupper
}
1331 \constfunc{wxString
}{Upper
}{\void}
1333 Returns this string converted to upper case.
1336 \membersection{wxString::UpperCase
}\label{wxstringuppercase
}
1338 \func{void
}{UpperCase
}{\void}
1340 The same as MakeUpper.
1342 This is a wxWidgets
1.xx compatibility function; you should not use it in new code.
1345 \membersection{wxString::utf8
\_str}\label{wxstringutf8str
}
1347 \constfunc{const char*
}{utf8
\_str}{\void}
1349 \constfunc{const wxCharBuffer
}{utf8
\_str}{\void}
1351 Converts the strings contents to UTF-
8 and returns it either as a temporary
1352 wxCharBuffer object or as a pointer to the internal string contents in
1354 % FIXME-UTF8: link to a topic explaining UTF-8 build here
1357 \membersection{wxString::wc
\_str}\label{wxstringwcstr
}
1359 \constfunc{const wchar
\_t*
}{wc
\_str}{\param{const wxMBConv\&
}{ conv
}}
1361 \constfunc{const wxWCharBuffer
}{wc
\_str}{\param{const wxMBConv\&
}{ conv
}}
1363 Returns wide character representation of the string.
1364 In ANSI build, converts using
\arg{conv
}'s
\helpref{cMB2WC
}{wxmbconvcmb2wc
}
1365 method and returns wxWCharBuffer. In Unicode build, this function is same
1366 as
\helpref{c
\_str}{wxstringcstr
}.
1367 The macro wxWX2WCbuf is defined as the correct return type (without const).
1369 \wxheading{See also
}
1371 \helpref{wxMBConv
}{wxmbconv
},
1372 \helpref{c
\_str}{wxstringcstr
},
\helpref{mb
\_str}{wxstringwcstr
},
1373 \helpref{fn
\_str}{wxstringfnstr
},
\helpref{wchar
\_str}{wxstringwcharstr
}
1375 \membersection{wxString::wchar
\_str}\label{wxstringwcharstr
}
1377 \constfunc{wxWritableWCharBuffer
}{wchar
\_str}{\void}
1379 Returns an object with string data that is implicitly convertible to
1380 {\tt char*
} pointer. Note that changes to the returned buffer may or may
1381 not be lost (depending on the build) and so this function is only usable for
1382 passing strings to legacy libraries that don't have const-correct API. Use
1383 \helpref{wxStringBuffer
}{wxstringbuffer
} if you want to modify the string.
1385 \wxheading{See also
}
1387 \helpref{mb
\_str}{wxstringmbstr
},
\helpref{wc
\_str}{wxstringwcstr
},
1388 \helpref{fn
\_str}{wxstringfnstr
},
\helpref{c
\_str}{wxstringcstr
},
1389 \helpref{char
\_str}{wxstringcharstr
}
1392 \membersection{wxString::operator!
}\label{wxstringoperatornot
}
1394 \constfunc{bool
}{operator!
}{\void}
1396 Empty string is
\false, so !string will only return
\true if the string is empty.
1397 This allows the tests for NULLness of a
{\it const wxChar *
} pointer and emptiness
1398 of the string to look the same in the code and makes it easier to port old code
1401 See also
\helpref{IsEmpty()
}{wxstringisempty
}.
1404 \membersection{wxString::operator $=$
}\label{wxstringoperatorassign
}
1406 \func{wxString\&
}{operator $=$
}{\param{const wxString\&
}{ str
}}
1408 \func{wxString\&
}{operator $=$
}{\param{const wxChar*
}{ psz
}}
1410 \func{wxString\&
}{operator $=$
}{\param{wxChar
}{ c
}}
1412 Assignment: the effect of each operation is the same as for the corresponding
1413 constructor (see
\helpref{wxString constructors
}{wxstringconstruct
}).
1416 \membersection{wxString::operator $+$
}\label{wxstringoperatorplus
}
1418 Concatenation: all these operators return a new string equal to the
1419 concatenation of the operands.
1421 \func{wxString
}{operator $+$
}{\param{const wxString\&
}{ x
},
\param{const wxString\&
}{ y
}}
1423 \func{wxString
}{operator $+$
}{\param{const wxString\&
}{ x
},
\param{const wxChar*
}{ y
}}
1425 \func{wxString
}{operator $+$
}{\param{const wxString\&
}{ x
},
\param{wxChar
}{ y
}}
1427 \func{wxString
}{operator $+$
}{\param{const wxChar*
}{ x
},
\param{const wxString\&
}{ y
}}
1430 \membersection{wxString::operator $+=$
}\label{wxstringplusequal
}
1432 \func{void
}{operator $+=$
}{\param{const wxString\&
}{ str
}}
1434 \func{void
}{operator $+=$
}{\param{const wxChar*
}{ psz
}}
1436 \func{void
}{operator $+=$
}{\param{wxChar
}{ c
}}
1438 Concatenation in place: the argument is appended to the string.
1441 \membersection{wxString::operator
[]}\label{wxstringoperatorbracket
}
1443 \func{wxChar\&
}{operator
[]}{\param{size
\_t}{ i
}}
1445 \constfunc{wxChar
}{operator
[]}{\param{size
\_t}{ i
}}
1447 \func{wxChar\&
}{operator
[]}{\param{int
}{ i
}}
1449 \constfunc{wxChar
}{operator
[]}{\param{int
}{ i
}}
1454 \membersection{wxString::operator ()
}\label{wxstringoperatorparenth
}
1456 \func{wxString
}{operator ()
}{\param{size
\_t}{ start
},
\param{size
\_t}{ len
}}
1458 Same as Mid (substring extraction).
1461 \membersection{wxString::operator
\cinsert}\label{wxstringoperatorout
}
1463 \func{wxString\&
}{operator
\cinsert}{\param{const wxString\&
}{ str
}}
1465 \func{wxString\&
}{operator
\cinsert}{\param{const wxChar*
}{ psz
}}
1467 \func{wxString\&
}{operator
\cinsert}{\param{wxChar
}{ch
}}
1471 \func{wxString\&
}{operator
\cinsert}{\param{int
}{ i
}}
1473 \func{wxString\&
}{operator
\cinsert}{\param{float
}{ f
}}
1475 \func{wxString\&
}{operator
\cinsert}{\param{double
}{ d
}}
1477 These functions work as C++ stream insertion operators: they insert the given
1478 value into the string. Precision or format cannot be set using them, you can use
1479 \helpref{Printf
}{wxstringprintf
} for this.
1482 \membersection{wxString::operator
\cextract}\label{wxstringoperatorin
}
1484 \func{friend istream\&
}{operator
\cextract}{\param{istream\&
}{ is
},
\param{wxString\&
}{ str
}}
1486 Extraction from a stream.
1489 \membersection{wxString::operator const wxChar*
}\label{wxstringoperatorconstcharpt
}
1491 \constfunc{}{operator const wxChar*
}{\void}
1493 Implicit conversion to a C string.
1496 \membersection{Comparison operators
}\label{wxstringcomparison
}
1498 \func{bool
}{operator $==$
}{\param{const wxString\&
}{ x
},
\param{const wxString\&
}{ y
}}
1500 \func{bool
}{operator $==$
}{\param{const wxString\&
}{ x
},
\param{const wxChar*
}{ t
}}
1502 \func{bool
}{operator $!=$
}{\param{const wxString\&
}{ x
},
\param{const wxString\&
}{ y
}}
1504 \func{bool
}{operator $!=$
}{\param{const wxString\&
}{ x
},
\param{const wxChar*
}{ t
}}
1506 \func{bool
}{operator $>$
}{\param{const wxString\&
}{ x
},
\param{const wxString\&
}{ y
}}
1508 \func{bool
}{operator $>$
}{\param{const wxString\&
}{ x
},
\param{const wxChar*
}{ t
}}
1510 \func{bool
}{operator $>=$
}{\param{const wxString\&
}{ x
},
\param{const wxString\&
}{ y
}}
1512 \func{bool
}{operator $>=$
}{\param{const wxString\&
}{ x
},
\param{const wxChar*
}{ t
}}
1514 \func{bool
}{operator $<$
}{\param{const wxString\&
}{ x
},
\param{const wxString\&
}{ y
}}
1516 \func{bool
}{operator $<$
}{\param{const wxString\&
}{ x
},
\param{const wxChar*
}{ t
}}
1518 \func{bool
}{operator $<=$
}{\param{const wxString\&
}{ x
},
\param{const wxString\&
}{ y
}}
1520 \func{bool
}{operator $<=$
}{\param{const wxString\&
}{ x
},
\param{const wxChar*
}{ t
}}
1524 These comparisons are case-sensitive.
1527 \section{\class{wxStringBuffer
}}\label{wxstringbuffer
}
1529 This tiny class allows to conveniently access the
\helpref{wxString
}{wxstring
}
1530 internal buffer as a writable pointer without any risk of forgetting to restore
1531 the string to the usable state later.
1533 For example, assuming you have a low-level OS function called
1534 {\tt GetMeaningOfLifeAsString(char *)
} returning the value in the provided
1535 buffer (which must be writable, of course) you might call it like this:
1539 GetMeaningOfLifeAsString(wxStringBuffer(theAnswer,
1024));
1540 if ( theAnswer != "
42" )
1542 wxLogError("Something is very wrong!");
1546 Note that the exact usage of this depends on whether on not wxUSE
\_STL is enabled. If
1547 wxUSE
\_STL is enabled, wxStringBuffer creates a separate empty character buffer, and
1548 if wxUSE
\_STL is disabled, it uses GetWriteBuf() from wxString, keeping the same buffer
1549 wxString uses intact. In other words, relying on wxStringBuffer containing the old
1550 wxString data is probably not a good idea if you want to build your program in both
1551 with and without wxUSE
\_STL.
1553 \wxheading{Derived from
}
1557 \wxheading{Include files
}
1561 \latexignore{\rtfignore{\wxheading{Members
}}}
1564 \membersection{wxStringBuffer::wxStringBuffer
}\label{wxstringbufferctor
}
1566 \func{}{wxStringBuffer
}{\param{const wxString\&
}{str
},
\param{size
\_t }{len
}}
1568 Constructs a writable string buffer object associated with the given string
1569 and containing enough space for at least
{\it len
} characters. Basically, this
1570 is equivalent to calling
\helpref{GetWriteBuf
}{wxstringgetwritebuf
} and
1574 \membersection{wxStringBuffer::
\destruct{wxStringBuffer
}}\label{wxstringbufferdtor
}
1576 \func{}{\destruct{wxStringBuffer
}}{\void}
1578 Restores the string passed to the constructor to the usable state by calling
1579 \helpref{UngetWriteBuf
}{wxstringungetwritebuf
} on it.
1582 \membersection{wxStringBuffer::operator wxChar *
}\label{wxstringbufferwxchar
}
1584 \func{wxChar *
}{operator wxChar *
}{\void}
1586 Returns the writable pointer to a buffer of the size at least equal to the
1587 length specified in the constructor.
1591 \section{\class{wxStringBufferLength
}}\label{wxstringbufferlength
}
1593 This tiny class allows to conveniently access the
\helpref{wxString
}{wxstring
}
1594 internal buffer as a writable pointer without any risk of forgetting to restore
1595 the string to the usable state later, and allows the user to set the internal
1596 length of the string.
1598 For example, assuming you have a low-level OS function called
1599 {\tt int GetMeaningOfLifeAsString(char *)
} copying the value in the provided
1600 buffer (which must be writable, of course), and returning the actual length
1601 of the string, you might call it like this:
1605 wxStringBuffer theAnswerBuffer(theAnswer,
1024);
1606 int nLength = GetMeaningOfLifeAsString(theAnswerBuffer);
1607 theAnswerBuffer.SetLength(nLength);
1608 if ( theAnswer != "
42" )
1610 wxLogError("Something is very wrong!");
1614 Note that the exact usage of this depends on whether on not wxUSE
\_STL is enabled. If
1615 wxUSE
\_STL is enabled, wxStringBuffer creates a separate empty character buffer, and
1616 if wxUSE
\_STL is disabled, it uses GetWriteBuf() from wxString, keeping the same buffer
1617 wxString uses intact. In other words, relying on wxStringBuffer containing the old
1618 wxString data is probably not a good idea if you want to build your program in both
1619 with and without wxUSE
\_STL.
1621 Note that SetLength
{\tt must
} be called before wxStringBufferLength destructs.
1623 \wxheading{Derived from
}
1627 \wxheading{Include files
}
1631 \latexignore{\rtfignore{\wxheading{Members
}}}
1634 \membersection{wxStringBufferLength::wxStringBufferLength
}\label{wxstringbufferlengthctor
}
1636 \func{}{wxStringBufferLength
}{\param{const wxString\&
}{str
},
\param{size
\_t }{len
}}
1638 Constructs a writable string buffer object associated with the given string
1639 and containing enough space for at least
{\it len
} characters. Basically, this
1640 is equivalent to calling
\helpref{GetWriteBuf
}{wxstringgetwritebuf
} and
1644 \membersection{wxStringBufferLength::
\destruct{wxStringBufferLength
}}\label{wxstringbufferlengthdtor
}
1646 \func{}{\destruct{wxStringBufferLength
}}{\void}
1648 Restores the string passed to the constructor to the usable state by calling
1649 \helpref{UngetWriteBuf
}{wxstringungetwritebuf
} on it.
1652 \membersection{wxStringBufferLength::SetLength
}\label{wxstringbufferlengthsetlength
}
1654 \func{void
}{SetLength
}{\param{size
\_t }{nLength
}}
1656 Sets the internal length of the string referred to by wxStringBufferLength to
1657 {\it nLength
} characters.
1659 Must be called before wxStringBufferLength destructs.
1662 \membersection{wxStringBufferLength::operator wxChar *
}\label{wxstringbufferlengthwxchar
}
1664 \func{wxChar *
}{operator wxChar *
}{\void}
1666 Returns the writable pointer to a buffer of the size at least equal to the
1667 length specified in the constructor.