]> git.saurik.com Git - wxWidgets.git/blame - docs/latex/wx/wxstring.tex
translate VK_OEM_PLUS to '=', not '+', because this is what the unmodified key is
[wxWidgets.git] / docs / latex / wx / wxstring.tex
CommitLineData
a660d684
KB
1\section{\class{wxString}}\label{wxstring}
2
40b480c3
JS
3wxString is a class representing a character string. Please see the
4\helpref{wxString overview}{wxstringoverview} for more information about it. As explained
5there, wxString implements about 90\% of methods of the std::string class (iterators
6are not supported, nor all methods which use them).
7These standard functions are not documented in this manual so please see the STL documentation.
99f09bc1 8The behaviour of all these functions is identical to the behaviour described
e2101186 9there (except that wxString is sensitive to null character).
99f09bc1 10
0aa35d19
VZ
11You may notice that wxString sometimes has many functions which do the same
12thing like, for example, \helpref{Length()}{wxstringlength},
13\helpref{Len()}{wxstringlen} and {\tt length()} which all return the string
14length. In all cases of such duplication the {\tt std::string}-compatible
15method ({\tt length()} in this case, always the lowercase version) should be
fc2171bd 16used as it will ensure smoother transition to {\tt std::string} when wxWidgets
0aa35d19
VZ
17starts using it instead of wxString.
18
b3324be2
JS
19\wxheading{Derived from}
20
21None
a660d684 22
954b8ae6
JS
23\wxheading{Include files}
24
25<wx/string.h>
26
20e85460
JS
27\wxheading{Predefined objects}
28
29Objects:
30
31{\bf wxEmptyString}
32
b3324be2
JS
33\wxheading{See also}
34
35\overview{Overview}{wxstringoverview}
a660d684 36
99f09bc1
VZ
37\latexignore{\rtfignore{\wxheading{Function groups}}}
38
15d83f72 39\membersection{Constructors and assignment operators}\label{constructorsinwxstring}
99f09bc1 40
2edb0bde 41A string may be constructed either from a C string, (some number of copies of)
99f09bc1
VZ
42a single character or a wide (UNICODE) string. For all constructors (except the
43default which creates an empty string) there is also a corresponding assignment
44operator.
45
46\helpref{wxString}{wxstringconstruct}\\
47\helpref{operator $=$}{wxstringoperatorassign}\\
48\helpref{\destruct{wxString}}{wxstringdestruct}
49
15d83f72 50\membersection{String length}\label{lengthfunctionsinwxstring}
99f09bc1
VZ
51
52These functions return the string length and check whether the string is empty
53or empty it.
54
55\helpref{Len}{wxstringlen}\\
56\helpref{IsEmpty}{wxstringisempty}\\
57\helpref{operator!}{wxstringoperatornot}\\
58\helpref{Empty}{wxstringempty}\\
59\helpref{Clear}{wxstringclear}
60
15d83f72 61\membersection{Character access}\label{characteraccessinwxstring}
99f09bc1
VZ
62
63Many functions in this section take a character index in the string. As with C
64strings and/or arrays, the indices start from $0$, so the first character of a
65string is string[$0$]. Attempt to access a character beyond the end of the
2edb0bde 66string (which may be even $0$ if the string is empty) will provoke an assert
99f09bc1
VZ
67failure in \helpref{debug build}{debuggingoverview}, but no checks are done in
68release builds.
69
70This section also contains both implicit and explicit conversions to C style
71strings. Although implicit conversion is quite convenient, it is advised to use
72explicit \helpref{c\_str()}{wxstringcstr} method for the sake of clarity. Also
fd34e3a5 73see \helpref{overview}{wxstringadvices} for the cases where it is necessary to
99f09bc1
VZ
74use it.
75
76\helpref{GetChar}{wxstringgetchar}\\
77\helpref{GetWritableChar}{wxstringgetwritablechar}\\
78\helpref{SetChar}{wxstringsetchar}\\
79\helpref{Last}{wxstringlast}\\
80\helpref{operator []}{wxstringoperatorbracket}\\
81\helpref{c\_str}{wxstringcstr}\\
bd8465ff
VS
82\helpref{mb\_str}{wxstringmbstr}\\
83\helpref{wc\_str}{wxstringwcstr}\\
84\helpref{fn\_str}{wxstringfnstr}\\
99f09bc1
VZ
85\helpref{operator const char*}{wxstringoperatorconstcharpt}
86
15d83f72 87\membersection{Concatenation}\label{concatenationinwxstring}
99f09bc1
VZ
88
89Anything may be concatenated (appended to) with a string. However, you can't
90append something to a C string (including literal constants), so to do this it
91should be converted to a wxString first.
92
93\helpref{operator \cinsert}{wxstringoperatorout}\\
94\helpref{operator $+=$}{wxstringplusequal}\\
95\helpref{operator $+$}{wxstringoperatorplus}\\
96\helpref{Append}{wxstringappend}\\
97\helpref{Prepend}{wxstringprepend}
98
15d83f72 99\membersection{Comparison}\label{comparisoninwxstring}
99f09bc1
VZ
100
101The default comparison function \helpref{Cmp}{wxstringcmp} is case-sensitive and
102so is the default version of \helpref{IsSameAs}{wxstringissameas}. For case
103insensitive comparisons you should use \helpref{CmpNoCase}{wxstringcmpnocase} or
104give a second parameter to IsSameAs. This last function is may be more
105convenient if only equality of the strings matters because it returns a boolean
cc81d32f 106true value if the strings are the same and not 0 (which is usually false in C)
f6bcfd97 107as {\tt Cmp()} does.
99f09bc1
VZ
108
109\helpref{Matches}{wxstringmatches} is a poor man's regular expression matcher:
110it only understands '*' and '?' metacharacters in the sense of DOS command line
111interpreter.
112
f6bcfd97
BP
113\helpref{StartsWith}{wxstringstartswith} is helpful when parsing a line of
114text which should start with some predefined prefix and is more efficient than
2edb0bde 115doing direct string comparison as you would also have to precalculate the
f6bcfd97
BP
116length of the prefix then.
117
99f09bc1
VZ
118\helpref{Cmp}{wxstringcmp}\\
119\helpref{CmpNoCase}{wxstringcmpnocase}\\
120\helpref{IsSameAs}{wxstringissameas}\\
f6bcfd97
BP
121\helpref{Matches}{wxstringmatches}\\
122\helpref{StartsWith}{wxstringstartswith}
99f09bc1 123
15d83f72 124\membersection{Substring extraction}\label{substringextractioninwxstring}
99f09bc1
VZ
125
126These functions allow to extract substring from this string. All of them don't
127modify the original string and return a new string containing the extracted
128substring.
129
130\helpref{Mid}{wxstringmid}\\
131\helpref{operator()}{wxstringoperatorparenth}\\
132\helpref{Left}{wxstringleft}\\
133\helpref{Right}{wxstringright}\\
134\helpref{BeforeFirst}{wxstringbeforefirst}\\
135\helpref{BeforeLast}{wxstringbeforelast}\\
136\helpref{AfterFirst}{wxstringafterfirst}\\
f6bcfd97
BP
137\helpref{AfterLast}{wxstringafterlast}\\
138\helpref{StartsWith}{wxstringstartswith}
99f09bc1 139
15d83f72 140\membersection{Case conversion}\label{caseconversioninwxstring}
99f09bc1
VZ
141
142The MakeXXX() variants modify the string in place, while the other functions
2edb0bde 143return a new string which contains the original text converted to the upper or
99f09bc1
VZ
144lower case and leave the original string unchanged.
145
146\helpref{MakeUpper}{wxstringmakeupper}\\
147\helpref{Upper}{wxstringupper}\\
148\helpref{MakeLower}{wxstringmakelower}\\
149\helpref{Lower}{wxstringlower}
150
15d83f72 151\membersection{Searching and replacing}\label{searchingandreplacinginwxstring}
99f09bc1 152
40b480c3 153These functions replace the standard {\it strchr()} and {\it strstr()}
99f09bc1
VZ
154functions.
155
156\helpref{Find}{wxstringfind}\\
157\helpref{Replace}{wxstringreplace}
158
15d83f72 159\membersection{Conversion to numbers}\label{conversiontonumbersinwxstring}
cd0b1709
VZ
160
161The string provides functions for conversion to signed and unsigned integer and
162floating point numbers. All three functions take a pointer to the variable to
cc81d32f 163put the numeric value in and return true if the {\bf entire} string could be
cd0b1709
VZ
164converted to a number.
165
166\helpref{ToLong}{wxstringtolong}\\
167\helpref{ToULong}{wxstringtoulong}\\
168\helpref{ToDouble}{wxstringtodouble}
169
15d83f72 170\membersection{Writing values into the string}\label{writingintostringinwxstring}
99f09bc1
VZ
171
172Both formatted versions (\helpref{Printf}{wxstringprintf}) and stream-like
341e7d28
VZ
173insertion operators exist (for basic types only). Additionally, the
174\helpref{Format}{wxstringformat} function allows to use simply append
175formatted value to a string:
99f09bc1 176
341e7d28
VZ
177\begin{verbatim}
178 // the following 2 snippets are equivalent
179
180 wxString s = "...";
181 s += wxString::Format("%d", n);
182
183 wxString s;
184 s.Printf("...%d", n);
185\end{verbatim}
186
187\helpref{Format}{wxstringformat}\\
188\helpref{FormatV}{wxstringformatv}\\
99f09bc1
VZ
189\helpref{Printf}{wxstringprintf}\\
190\helpref{PrintfV}{wxstringprintfv}\\
40b480c3 191\helpref{operator \cinsert}{wxstringoperatorout}
99f09bc1 192
15d83f72 193\membersection{Memory management}\label{memoryinwxstring}
99f09bc1 194
2edb0bde 195These are "advanced" functions and they will be needed quite rarely.
99f09bc1
VZ
196\helpref{Alloc}{wxstringalloc} and \helpref{Shrink}{wxstringshrink} are only
197interesting for optimization purposes.
198\helpref{GetWriteBuf}{wxstringgetwritebuf} may be very useful when working with
199some external API which requires the caller to provide a writable buffer, but
200extreme care should be taken when using it: before performing any other
201operation on the string \helpref{UngetWriteBuf}{wxstringungetwritebuf} {\bf
202must} be called!
203
204\helpref{Alloc}{wxstringalloc}\\
205\helpref{Shrink}{wxstringshrink}\\
206\helpref{GetWriteBuf}{wxstringgetwritebuf}\\
207\helpref{UngetWriteBuf}{wxstringungetwritebuf}
208
15d83f72 209\membersection{Miscellaneous}\label{miscellaneousinwxstring}
99f09bc1
VZ
210
211Other string functions.
212
213\helpref{Trim}{wxstringtrim}\\
214\helpref{Pad}{wxstringpad}\\
215\helpref{Truncate}{wxstringtruncate}
216
15d83f72 217\membersection{wxWidgets 1.xx compatibility functions}\label{backwardcompatibilityinwxstring}
99f09bc1 218
fc2171bd 219These functions are deprecated, please consider using new wxWidgets 2.0
99f09bc1
VZ
220functions instead of them (or, even better, std::string compatible variants).
221
222\helpref{SubString}{wxstringsubstring}\\
223\helpref{sprintf}{wxstringsprintf}\\
224\helpref{CompareTo}{wxstringcompareto}\\
225\helpref{Length}{wxstringlength}\\
226\helpref{Freq}{wxstringfreq}\\
227\helpref{LowerCase}{wxstringlowercase}\\
228\helpref{UpperCase}{wxstringuppercase}\\
229\helpref{Strip}{wxstringstrip}\\
230\helpref{Index}{wxstringindex}\\
231\helpref{Remove}{wxstringremove}\\
232\helpref{First}{wxstringfirst}\\
233\helpref{Last}{wxstringlast}\\
234\helpref{Contains}{wxstringcontains}\\
235\helpref{IsNull}{wxstringisnull}\\
236\helpref{IsAscii}{wxstringisascii}\\
237\helpref{IsNumber}{wxstringisnumber}\\
238\helpref{IsWord}{wxstringisword}
239
ed93168b 240\membersection{std::string compatibility functions}\label{wxstringat}
99f09bc1
VZ
241
242The supported functions are only listed here, please see any STL reference for
243their documentation.
244
245\begin{verbatim}
246 // take nLen chars starting at nPos
247 wxString(const wxString& str, size_t nPos, size_t nLen);
248 // take all characters from pStart to pEnd (poor man's iterators)
249 wxString(const void *pStart, const void *pEnd);
250
251 // lib.string.capacity
252 // return the length of the string
253 size_t size() const;
254 // return the length of the string
255 size_t length() const;
256 // return the maximum size of the string
257 size_t max_size() const;
258 // resize the string, filling the space with c if c != 0
259 void resize(size_t nSize, char ch = '\0');
260 // delete the contents of the string
261 void clear();
262 // returns true if the string is empty
263 bool empty() const;
264
265 // lib.string.access
266 // return the character at position n
267 char at(size_t n) const;
268 // returns the writable character at position n
269 char& at(size_t n);
270
271 // lib.string.modifiers
272 // append a string
273 wxString& append(const wxString& str);
274 // append elements str[pos], ..., str[pos+n]
275 wxString& append(const wxString& str, size_t pos, size_t n);
276 // append first n (or all if n == npos) characters of sz
277 wxString& append(const char *sz, size_t n = npos);
278
279 // append n copies of ch
280 wxString& append(size_t n, char ch);
281
282 // same as `this_string = str'
283 wxString& assign(const wxString& str);
284 // same as ` = str[pos..pos + n]
285 wxString& assign(const wxString& str, size_t pos, size_t n);
286 // same as `= first n (or all if n == npos) characters of sz'
287 wxString& assign(const char *sz, size_t n = npos);
288 // same as `= n copies of ch'
289 wxString& assign(size_t n, char ch);
290
291 // insert another string
292 wxString& insert(size_t nPos, const wxString& str);
293 // insert n chars of str starting at nStart (in str)
294 wxString& insert(size_t nPos, const wxString& str, size_t nStart, size_t n);
295
296 // insert first n (or all if n == npos) characters of sz
297 wxString& insert(size_t nPos, const char *sz, size_t n = npos);
298 // insert n copies of ch
299 wxString& insert(size_t nPos, size_t n, char ch);
300
301 // delete characters from nStart to nStart + nLen
302 wxString& erase(size_t nStart = 0, size_t nLen = npos);
303
304 // replaces the substring of length nLen starting at nStart
305 wxString& replace(size_t nStart, size_t nLen, const char* sz);
306 // replaces the substring with nCount copies of ch
307 wxString& replace(size_t nStart, size_t nLen, size_t nCount, char ch);
308 // replaces a substring with another substring
309 wxString& replace(size_t nStart, size_t nLen,
310 const wxString& str, size_t nStart2, size_t nLen2);
311 // replaces the substring with first nCount chars of sz
312 wxString& replace(size_t nStart, size_t nLen,
313 const char* sz, size_t nCount);
314
315 // swap two strings
316 void swap(wxString& str);
317
318 // All find() functions take the nStart argument which specifies the
319 // position to start the search on, the default value is 0. All functions
320 // return npos if there were no match.
321
322 // find a substring
323 size_t find(const wxString& str, size_t nStart = 0) const;
324
325 // find first n characters of sz
326 size_t find(const char* sz, size_t nStart = 0, size_t n = npos) const;
327
7335902d 328 // find the first occurrence of character ch after nStart
99f09bc1
VZ
329 size_t find(char ch, size_t nStart = 0) const;
330
331 // rfind() family is exactly like find() but works right to left
332
333 // as find, but from the end
334 size_t rfind(const wxString& str, size_t nStart = npos) const;
335
336 // as find, but from the end
337 size_t rfind(const char* sz, size_t nStart = npos,
338 size_t n = npos) const;
339 // as find, but from the end
340 size_t rfind(char ch, size_t nStart = npos) const;
341
7335902d 342 // find first/last occurrence of any character in the set
99f09bc1
VZ
343
344 //
345 size_t find_first_of(const wxString& str, size_t nStart = 0) const;
346 //
347 size_t find_first_of(const char* sz, size_t nStart = 0) const;
348 // same as find(char, size_t)
349 size_t find_first_of(char c, size_t nStart = 0) const;
350 //
351 size_t find_last_of (const wxString& str, size_t nStart = npos) const;
352 //
353 size_t find_last_of (const char* s, size_t nStart = npos) const;
354 // same as rfind(char, size_t)
355 size_t find_last_of (char c, size_t nStart = npos) const;
356
7335902d 357 // find first/last occurrence of any character not in the set
99f09bc1
VZ
358
359 //
360 size_t find_first_not_of(const wxString& str, size_t nStart = 0) const;
361 //
362 size_t find_first_not_of(const char* s, size_t nStart = 0) const;
363 //
364 size_t find_first_not_of(char ch, size_t nStart = 0) const;
365 //
366 size_t find_last_not_of(const wxString& str, size_t nStart=npos) const;
367 //
368 size_t find_last_not_of(const char* s, size_t nStart = npos) const;
369 //
370 size_t find_last_not_of(char ch, size_t nStart = npos) const;
371
372 // All compare functions return a negative, zero or positive value
373 // if the [sub]string is less, equal or greater than the compare() argument.
374
375 // just like strcmp()
376 int compare(const wxString& str) const;
377 // comparison with a substring
378 int compare(size_t nStart, size_t nLen, const wxString& str) const;
379 // comparison of 2 substrings
380 int compare(size_t nStart, size_t nLen,
381 const wxString& str, size_t nStart2, size_t nLen2) const;
382 // just like strcmp()
383 int compare(const char* sz) const;
384 // substring comparison with first nCount characters of sz
385 int compare(size_t nStart, size_t nLen,
386 const char* sz, size_t nCount = npos) const;
387
388 // substring extraction
389 wxString substr(size_t nStart = 0, size_t nLen = npos) const;
390\end{verbatim}
391
392%%%%% MEMBERS HERE %%%%%
393\helponly{\insertatlevel{2}{
394
395\wxheading{Members}
396
397}}
a660d684
KB
398
399\membersection{wxString::wxString}\label{wxstringconstruct}
400
b3324be2 401\func{}{wxString}{\void}
a660d684 402
bd8465ff 403Default constructor. Initializes the string to {\tt ""} (empty string).
a660d684 404
b3324be2 405\func{}{wxString}{\param{const wxString\&}{ x}}
a660d684 406
b3324be2 407Copy constructor.
a660d684 408
b3324be2 409\func{}{wxString}{\param{char}{ ch}, \param{size\_t}{ n = 1}}
a660d684 410
b3324be2 411Constructs a string of {\it n} copies of character {\it ch}.
a660d684 412
99f09bc1 413\func{}{wxString}{\param{const char*}{ psz}, \param{size\_t}{ nLength = wxSTRING\_MAXLEN}}
a660d684 414
b3324be2 415Takes first {\it nLength} characters from the C string {\it psz}.
bd8465ff 416The default value of {\tt wxSTRING\_MAXLEN} means to take all the string.
f6bcfd97
BP
417
418Note that this constructor may be used even if {\it psz} points to a buffer
419with binary data (i.e. containing {\tt NUL} characters) as long as you provide
420the correct value for {\it nLength}. However, the default form of it works
421only with strings without intermediate {\tt NUL}s because it uses
422{\tt strlen()} to calculate the effective length and it would not give correct
423results otherwise.
a660d684 424
99f09bc1 425\func{}{wxString}{\param{const unsigned char*}{ psz}, \param{size\_t}{ nLength = wxSTRING\_MAXLEN}}
a660d684 426
b3324be2 427For compilers using unsigned char: takes first {\it nLength} characters from the C string {\it psz}.
bd8465ff 428The default value of {\tt wxSTRING\_MAXLEN} means take all the string.
a660d684 429
bd8465ff
VS
430{\bf Note:} In Unicode build, all of the above constructors take
431{\tt wchar\_t} arguments instead of {\tt char}.
a660d684 432
bd8465ff
VS
433\wxheading{Constructors with conversion}
434
435The following constructors allow you to construct wxString from wide string
436in ANSI build or from C string in Unicode build.
437
438\func{}{wxString}{\param{const wchar\_t*}{ psz}, \param{wxMBConv\&}{ conv}, \param{size\_t}{ nLength = wxSTRING\_MAXLEN}}
439
440Initializes the string from first \arg{nLength} characters of wide string.
441The default value of {\tt wxSTRING\_MAXLEN} means take all the string.
442In ANSI build, \arg{conv}'s
443\helpref{WC2MB}{wxmbconvwc2mb} method is called to
444convert \arg{psz} to wide string. It is ignored in Unicode build.
445
446\func{}{wxString}{\param{const char*}{ psz}, \param{wxMBConv\&}{ conv}, \param{size\_t}{ nLength = wxSTRING\_MAXLEN}}
447
448Initializes the string from first \arg{nLength} characters of C string.
449The default value of {\tt wxSTRING\_MAXLEN} means take all the string.
450In Unicode build, \arg{conv}'s
451\helpref{MB2WC}{wxmbconvmb2wc} method is called to
452convert \arg{psz} to wide string. It is ignored in ANSI build.
453
454\wxheading{See also}
455
456\helpref{wxMBConv classes}{mbconvclasses}, \helpref{mb\_str}{wxstringmbstr},
457\helpref{wc\_str}{wxstringwcstr}
a660d684 458
b3324be2 459\membersection{wxString::\destruct{wxString}}\label{wxstringdestruct}
a660d684 460
b3324be2 461\func{}{\destruct{wxString}}{\void}
a660d684 462
b3324be2 463String destructor. Note that this is not virtual, so wxString must not be inherited from.
a660d684 464
99f09bc1
VZ
465\membersection{wxString::Alloc}\label{wxstringalloc}
466
467\func{void}{Alloc}{\param{size\_t}{ nLen}}
468
469Preallocate enough space for wxString to store {\it nLen} characters. This function
470may be used to increase speed when the string is constructed by repeated
471concatenation as in
472
473\begin{verbatim}
a660d684 474
99f09bc1
VZ
475// delete all vowels from the string
476wxString DeleteAllVowels(const wxString& original)
477{
478 wxString result;
a660d684 479
99f09bc1 480 size_t len = original.length();
a660d684 481
99f09bc1
VZ
482 result.Alloc(len);
483
484 for ( size_t n = 0; n < len; n++ )
485 {
486 if ( strchr("aeuio", tolower(original[n])) == NULL )
487 result += original[n];
488 }
489
490 return result;
491}
492
493\end{verbatim}
494
dbd94b75 495because it will avoid the need to reallocate string memory many times (in case
99f09bc1
VZ
496of long strings). Note that it does not set the maximal length of a string - it
497will still expand if more than {\it nLen} characters are stored in it. Also, it
498does not truncate the existing string (use
499\helpref{Truncate()}{wxstringtruncate} for this) even if its current length is
500greater than {\it nLen}
501
502\membersection{wxString::Append}\label{wxstringappend}
b3324be2
JS
503
504\func{wxString\&}{Append}{\param{const char*}{ psz}}
a660d684 505
b3324be2 506Concatenates {\it psz} to this string, returning a reference to it.
a660d684 507
b3324be2 508\func{wxString\&}{Append}{\param{char}{ ch}, \param{int}{ count = 1}}
a660d684 509
b3324be2
JS
510Concatenates character {\it ch} to this string, {\it count} times, returning a reference
511to it.
512
99f09bc1 513\membersection{wxString::AfterFirst}\label{wxstringafterfirst}
b3324be2 514
99f09bc1 515\constfunc{wxString}{AfterFirst}{\param{char}{ ch}}
b3324be2 516
7335902d 517Gets all the characters after the first occurrence of {\it ch}.
b3324be2 518Returns the empty string if {\it ch} is not found.
a660d684 519
99f09bc1 520\membersection{wxString::AfterLast}\label{wxstringafterlast}
a660d684 521
99f09bc1
VZ
522\constfunc{wxString}{AfterLast}{\param{char}{ ch}}
523
7335902d 524Gets all the characters after the last occurrence of {\it ch}.
99f09bc1
VZ
525Returns the whole string if {\it ch} is not found.
526
527\membersection{wxString::BeforeFirst}\label{wxstringbeforefirst}
528
529\constfunc{wxString}{BeforeFirst}{\param{char}{ ch}}
530
7335902d 531Gets all characters before the first occurrence of {\it ch}.
99f09bc1
VZ
532Returns the whole string if {\it ch} is not found.
533
534\membersection{wxString::BeforeLast}\label{wxstringbeforelast}
535
536\constfunc{wxString}{BeforeLast}{\param{char}{ ch}}
b3324be2 537
7335902d 538Gets all characters before the last occurrence of {\it ch}.
99f09bc1 539Returns the empty string if {\it ch} is not found.
a660d684 540
ed93168b
VZ
541\membersection{wxString::c\_str}\label{wxstringcstr}
542
543\constfunc{const char *}{c\_str}{\void}
544
bd8465ff
VS
545Returns a pointer to the string data ({\tt const char*} in ANSI build,
546{\tt const wchar\_t*} in Unicode build).
547
548\wxheading{See also}
549
550\helpref{mb\_str}{wxstringmbstr}, \helpref{wc\_str}{wxstringwcstr},
551\helpref{fn\_str}{wxstringfnstr}
ed93168b
VZ
552
553\membersection{wxString::Clear}\label{wxstringclear}
554
555\func{void}{Clear}{\void}
556
557Empties the string and frees memory occupied by it.
558
559See also: \helpref{Empty}{wxstringempty}
560
f7bd2698
JS
561\membersection{wxString::Cmp}\label{wxstringcmp}
562
563\constfunc{int}{Cmp}{\param{const char*}{ psz}}
564
565Case-sensitive comparison.
566
99f09bc1 567Returns a positive value if the string is greater than the argument, zero if
f6bcfd97 568it is equal to it or a negative value if it is less than the argument (same semantics
99f09bc1 569as the standard {\it strcmp()} function).
f7bd2698 570
99f09bc1 571See also \helpref{CmpNoCase}{wxstringcmpnocase}, \helpref{IsSameAs}{wxstringissameas}.
f7bd2698
JS
572
573\membersection{wxString::CmpNoCase}\label{wxstringcmpnocase}
574
575\constfunc{int}{CmpNoCase}{\param{const char*}{ psz}}
576
577Case-insensitive comparison.
578
99f09bc1 579Returns a positive value if the string is greater than the argument, zero if
f6bcfd97 580it is equal to it or a negative value if it is less than the argument (same semantics
99f09bc1 581as the standard {\it strcmp()} function).
f7bd2698 582
99f09bc1 583See also \helpref{Cmp}{wxstringcmp}, \helpref{IsSameAs}{wxstringissameas}.
f7bd2698 584
99f09bc1 585\membersection{wxString::CompareTo}\label{wxstringcompareto}
a660d684
KB
586
587\begin{verbatim}
588#define NO_POS ((int)(-1)) // undefined position
b3324be2 589enum caseCompare {exact, ignoreCase};
a660d684 590\end{verbatim}
ed93168b 591
b3324be2 592\constfunc{int}{CompareTo}{\param{const char*}{ psz}, \param{caseCompare}{ cmp = exact}}
a660d684 593
b3324be2 594Case-sensitive comparison. Returns 0 if equal, 1 if greater or -1 if less.
a660d684 595
99f09bc1 596\membersection{wxString::Contains}\label{wxstringcontains}
a660d684 597
99f09bc1 598\constfunc{bool}{Contains}{\param{const wxString\&}{ str}}
a660d684 599
dbd94b75 600Returns 1 if target appears anywhere in wxString; else 0.
a660d684 601
f7bd2698 602\membersection{wxString::Empty}\label{wxstringempty}
a660d684 603
f7bd2698
JS
604\func{void}{Empty}{\void}
605
ed93168b
VZ
606Makes the string empty, but doesn't free memory occupied by the string.
607
608See also: \helpref{Clear()}{wxstringclear}.
f7bd2698
JS
609
610\membersection{wxString::Find}\label{wxstringfind}
611
cc81d32f 612\constfunc{int}{Find}{\param{char}{ ch}, \param{bool}{ fromEnd = false}}
f7bd2698
JS
613
614Searches for the given character. Returns the starting index, or -1 if not found.
615
616\constfunc{int}{Find}{\param{const char*}{ sz}}
617
618Searches for the given string. Returns the starting index, or -1 if not found.
a660d684 619
b3324be2 620\membersection{wxString::First}\label{wxstringfirst}
a660d684 621
0aa35d19 622\func{int}{First}{\param{char}{ c}}
a660d684 623
0aa35d19 624\constfunc{int}{First}{\param{const char*}{ psz}}
a660d684 625
0aa35d19 626\constfunc{int}{First}{\param{const wxString\&}{ str}}
a660d684 627
0aa35d19 628Same as \helpref{Find}{wxstringfind}.
a660d684 629
bd8465ff
VS
630\membersection{wxString::fn\_str}\label{wxstringfnstr}
631
632\constfunc{const wchar\_t*}{fn\_str}{\void}
633
634\constfunc{const char*}{fn\_str}{\void}
635
636\constfunc{const wxCharBuffer}{fn\_str}{\void}
637
638Returns string representation suitable for passing to OS' functions for
639file handling. In ANSI build, this is same as \helpref{c\_str}{wxstringcstr}.
640In Unicode build, returned value can be either wide character string
641or C string in charset matching the {\tt wxConvFile} object, depending on
642the OS.
643
644\wxheading{See also}
645
646\helpref{wxMBConv}{wxmbconv},
647\helpref{wc\_str}{wxstringwcstr}, \helpref{mb\_str}{wxstringwcstr}
648
341e7d28
VZ
649\membersection{wxString::Format}\label{wxstringformat}
650
651\func{static wxString}{Format}{\param{const wxChar }{*format}, \param{}{...}}
652
653This static function returns the string containing the result of calling
654\helpref{Printf}{wxstringprintf} with the passed parameters on it.
655
656\wxheading{See also}
657
658\helpref{FormatV}{wxstringformatv}, \helpref{Printf}{wxstringprintf}
659
660\membersection{wxString::FormatV}\label{wxstringformatv}
661
662\func{static wxString}{Format}{\param{const wxChar }{*format}, \param{va\_list }{argptr}}
663
664This static function returns the string containing the result of calling
665\helpref{PrintfV}{wxstringprintfv} with the passed parameters on it.
666
667\wxheading{See also}
668
669\helpref{Format}{wxstringformat}, \helpref{PrintfV}{wxstringprintfv}
670
99f09bc1
VZ
671\membersection{wxString::Freq}\label{wxstringfreq}
672
f6bcfd97 673\constfunc{int}{Freq}{\param{char }{ch}}
99f09bc1 674
f6bcfd97 675Returns the number of occurrences of {\it ch} in the string.
99f09bc1 676
6d9d6350
JS
677\membersection{wxString::FromAscii}\label{wxstringfromascii}
678
679\func{static wxString }{FromAscii}{\param{const char*}{ s}}
680
681\func{static wxString }{FromAscii}{\param{const char}{ c}}
682
683Converts the string or character from an ASCII, 7-bit form
684to the native wxString representation. Most useful when using
fc2171bd 685a Unicode build of wxWidgets.
bd8465ff
VS
686Use \helpref{wxString constructors}{wxstringconstruct} if you
687need to convert from another charset.
6d9d6350 688
f7bd2698 689\membersection{wxString::GetChar}\label{wxstringgetchar}
a660d684 690
f7bd2698 691\constfunc{char}{GetChar}{\param{size\_t}{ n}}
a660d684 692
f7bd2698 693Returns the character at position {\it n} (read-only).
a660d684 694
99f09bc1 695\membersection{wxString::GetData}\label{wxstringgetdata}
a660d684 696
f7bd2698 697\constfunc{const char*}{GetData}{\void}
a660d684 698
fc2171bd 699wxWidgets compatibility conversion. Returns a constant pointer to the data in the string.
a660d684 700
f7bd2698 701\membersection{wxString::GetWritableChar}\label{wxstringgetwritablechar}
a660d684 702
f7bd2698 703\func{char\&}{GetWritableChar}{\param{size\_t}{ n}}
a660d684 704
f7bd2698 705Returns a reference to the character at position {\it n}.
a660d684 706
f7bd2698 707\membersection{wxString::GetWriteBuf}\label{wxstringgetwritebuf}
a660d684 708
9a55c2ee 709\func{wxChar*}{GetWriteBuf}{\param{size\_t}{ len}}
a660d684 710
f7bd2698 711Returns a writable buffer of at least {\it len} bytes.
8161ba08
JS
712It returns a pointer to a new memory block, and the
713existing data will not be copied.
a660d684 714
f7bd2698
JS
715Call \helpref{wxString::UngetWriteBuf}{wxstringungetwritebuf} as soon as possible
716to put the string back into a reasonable state.
a660d684 717
99f09bc1 718\membersection{wxString::Index}\label{wxstringindex}
a660d684 719
5ef056a3 720\constfunc{size\_t}{Index}{\param{char}{ ch}}
a660d684 721
f7bd2698 722\constfunc{size\_t}{Index}{\param{const char*}{ sz}}
a660d684 723
f7bd2698 724Same as \helpref{wxString::Find}{wxstringfind}.
a660d684 725
8a2c6ef8
JS
726% TODO
727%\membersection{wxString::insert}\label{wxstringinsert}
728% Wrong!
99f09bc1 729%\func{void}{insert}{\param{const wxString\&}{ str}, \param{size\_t}{ index}}
8a2c6ef8
JS
730%
731%Add new element at the given position.
732%
99f09bc1 733\membersection{wxString::IsAscii}\label{wxstringisascii}
a660d684 734
f7bd2698 735\constfunc{bool}{IsAscii}{\void}
a660d684 736
cc81d32f 737Returns true if the string contains only ASCII characters.
a660d684 738
f7bd2698 739\membersection{wxString::IsEmpty}\label{wxstringisempty}
a660d684 740
f7bd2698 741\constfunc{bool}{IsEmpty}{\void}
a660d684 742
cc81d32f 743Returns true if the string is empty.
a660d684 744
99f09bc1 745\membersection{wxString::IsNull}\label{wxstringisnull}
a660d684 746
f7bd2698 747\constfunc{bool}{IsNull}{\void}
a660d684 748
cc81d32f 749Returns true if the string is empty (same as \helpref{IsEmpty}{wxstringisempty}).
a660d684 750
99f09bc1 751\membersection{wxString::IsNumber}\label{wxstringisnumber}
a660d684 752
f7bd2698
JS
753\constfunc{bool}{IsNumber}{\void}
754
cc81d32f 755Returns true if the string is an integer (with possible sign).
f7bd2698
JS
756
757\membersection{wxString::IsSameAs}\label{wxstringissameas}
758
cc81d32f 759\constfunc{bool}{IsSameAs}{\param{const char*}{ psz}, \param{bool}{ caseSensitive = true}}
f7bd2698
JS
760
761Test for string equality, case-sensitive (default) or not.
762
cc81d32f 763caseSensitive is true by default (case matters).
a660d684 764
cc81d32f 765Returns true if strings are equal, false otherwise.
f7bd2698 766
4b4fae9b 767See also \helpref{Cmp}{wxstringcmp}, \helpref{CmpNoCase}{wxstringcmpnocase}
f33fee2a 768
cc81d32f 769\constfunc{bool}{IsSameAs}{\param{char}{ c}, \param{bool}{ caseSensitive = true}}
f33fee2a
VZ
770
771Test whether the string is equal to the single character {\it c}. The test is
cc81d32f 772case-sensitive if {\it caseSensitive} is true (default) or not if it is false.
f33fee2a 773
cc81d32f 774Returns true if the string is equal to the character, false otherwise.
f33fee2a 775
4b4fae9b 776See also \helpref{Cmp}{wxstringcmp}, \helpref{CmpNoCase}{wxstringcmpnocase}
a660d684 777
99f09bc1 778\membersection{wxString::IsWord}\label{wxstringisword}
a660d684 779
f7bd2698 780\constfunc{bool}{IsWord}{\void}
a660d684 781
cc81d32f 782Returns true if the string is a word. TODO: what's the definition of a word?
a660d684 783
99f09bc1 784\membersection{wxString::Last}\label{wxstringlast}
a660d684 785
f7bd2698 786\constfunc{char}{Last}{\void}
a660d684 787
f7bd2698 788Returns the last character.
a660d684 789
f7bd2698 790\func{char\&}{Last}{\void}
a660d684 791
f7bd2698 792Returns a reference to the last character (writable).
a660d684 793
f7bd2698
JS
794\membersection{wxString::Left}\label{wxstringleft}
795
796\constfunc{wxString}{Left}{\param{size\_t}{ count}}
797
fefc4f15 798Returns the first {\it count} characters of the string.
a660d684 799
f7bd2698 800\membersection{wxString::Len}\label{wxstringlen}
a660d684 801
f7bd2698
JS
802\constfunc{size\_t}{Len}{\void}
803
804Returns the length of the string.
805
806\membersection{wxString::Length}\label{wxstringlength}
807
808\constfunc{size\_t}{Length}{\void}
809
810Returns the length of the string (same as Len).
a660d684 811
99f09bc1
VZ
812\membersection{wxString::Lower}\label{wxstringlower}
813
814\constfunc{wxString}{Lower}{\void}
815
816Returns this string converted to the lower case.
817
818\membersection{wxString::LowerCase}\label{wxstringlowercase}
a660d684 819
f7bd2698
JS
820\func{void}{LowerCase}{\void}
821
822Same as MakeLower.
823
824\membersection{wxString::MakeLower}\label{wxstringmakelower}
825
e16f8973 826\func{wxString\&}{MakeLower}{\void}
f7bd2698 827
e16f8973 828Converts all characters to lower case and returns the result.
f7bd2698
JS
829
830\membersection{wxString::MakeUpper}\label{wxstringmakeupper}
831
e16f8973 832\func{wxString\&}{MakeUpper}{\void}
f7bd2698 833
e16f8973 834Converts all characters to upper case and returns the result.
a660d684 835
99f09bc1 836\membersection{wxString::Matches}\label{wxstringmatches}
a660d684 837
f7bd2698
JS
838\constfunc{bool}{Matches}{\param{const char*}{ szMask}}
839
cc81d32f 840Returns true if the string contents matches a mask containing '*' and '?'.
a660d684 841
bd8465ff
VS
842\membersection{wxString::mb\_str}\label{wxstringmbstr}
843
844\constfunc{const char*}{mb\_str}{\param{wxMBConv\&}{ conv}}
845
846\constfunc{const wxCharBuffer}{mb\_str}{\param{wxMBConv\&}{ conv}}
847
848Returns multibyte (C string) representation of the string.
849In Unicode build, converts using \arg{conv}'s \helpref{cWC2MB}{wxmbconvcwc2mb}
850method and returns wxCharBuffer. In ANSI build, this function is same
851as \helpref{c\_str}{wxstringcstr}.
852The macro wxWX2MBbuf is defined as the correct return type (without const).
853
854\wxheading{See also}
855
856\helpref{wxMBConv}{wxmbconv},
857\helpref{c\_str}{wxstringcstr}, \helpref{wc\_str}{wxstringwcstr},
858\helpref{fn\_str}{wxstringfnstr}
859
f7bd2698 860\membersection{wxString::Mid}\label{wxstringmid}
a660d684 861
99f09bc1 862\constfunc{wxString}{Mid}{\param{size\_t}{ first}, \param{size\_t}{ count = wxSTRING\_MAXLEN}}
a660d684 863
f7bd2698
JS
864Returns a substring starting at {\it first}, with length {\it count}, or the rest of
865the string if {\it count} is the default value.
866
867\membersection{wxString::Pad}\label{wxstringpad}
868
cc81d32f 869\func{wxString\&}{Pad}{\param{size\_t}{ count}, \param{char}{ pad = ' '}, \param{bool}{ fromRight = true}}
f7bd2698
JS
870
871Adds {\it count} copies of {\it pad} to the beginning, or to the end of the string (the default).
872
873Removes spaces from the left or from the right (default).
a660d684 874
99f09bc1 875\membersection{wxString::Prepend}\label{wxstringprepend}
a660d684 876
f7bd2698 877\func{wxString\&}{Prepend}{\param{const wxString\&}{ str}}
a660d684 878
f7bd2698 879Prepends {\it str} to this string, returning a reference to this string.
a660d684 880
f7bd2698 881\membersection{wxString::Printf}\label{wxstringprintf}
a660d684 882
f7bd2698
JS
883\func{int}{Printf}{\param{const char* }{pszFormat}, \param{}{...}}
884
99f09bc1
VZ
885Similar to the standard function {\it sprintf()}. Returns the number of
886characters written, or an integer less than zero on error.
887
888{\bf NB:} This function will use a safe version of {\it vsprintf()} (usually called
889{\it vsnprintf()}) whenever available to always allocate the buffer of correct
890size. Unfortunately, this function is not available on all platforms and the
891dangerous {\it vsprintf()} will be used then which may lead to buffer overflows.
a660d684 892
f7bd2698
JS
893\membersection{wxString::PrintfV}\label{wxstringprintfv}
894
895\func{int}{PrintfV}{\param{const char* }{pszFormat}, \param{va\_list}{ argPtr}}
896
897Similar to vprintf. Returns the number of characters written, or an integer less than zero
898on error.
a660d684 899
99f09bc1 900\membersection{wxString::Remove}\label{wxstringremove}
a660d684 901
f7bd2698
JS
902\func{wxString\&}{Remove}{\param{size\_t}{ pos}}
903
904Same as Truncate. Removes the portion from {\it pos} to the end of the string.
905
906\func{wxString\&}{Remove}{\param{size\_t}{ pos}, \param{size\_t}{ len}}
907
42d14d4e 908Removes the {\it len} characters from the string, starting at {\it pos}.
f7bd2698
JS
909
910\membersection{wxString::RemoveLast}\label{wxstringremovelast}
a660d684 911
f7bd2698
JS
912\func{wxString\&}{RemoveLast}{\void}
913
914Removes the last character.
a660d684 915
99f09bc1 916\membersection{wxString::Replace}\label{wxstringreplace}
a660d684 917
cc81d32f 918\func{size\_t}{Replace}{\param{const char*}{ szOld}, \param{const char*}{ szNew}, \param{bool}{ replaceAll = true}}
f7bd2698 919
7335902d 920Replace first (or all) occurrences of substring with another one.
f7bd2698 921
7335902d 922{\it replaceAll}: global replace (default), or only the first occurrence.
f7bd2698
JS
923
924Returns the number of replacements made.
925
926\membersection{wxString::Right}\label{wxstringright}
927
928\constfunc{wxString}{Right}{\param{size\_t}{ count}}
a660d684 929
f7bd2698 930Returns the last {\it count} characters.
a660d684 931
f7bd2698 932\membersection{wxString::SetChar}\label{wxstringsetchar}
a660d684 933
f7bd2698
JS
934\func{void}{SetChar}{\param{size\_t}{ n}, \param{char}{ch}}
935
936Sets the character at position {\it n}.
937
938\membersection{wxString::Shrink}\label{wxstringshrink}
939
940\func{void}{Shrink}{\void}
941
99f09bc1
VZ
942Minimizes the string's memory. This can be useful after a call to
943\helpref{Alloc()}{wxstringalloc} if too much memory were preallocated.
a660d684
KB
944
945\membersection{wxString::sprintf}\label{wxstringsprintf}
a660d684 946
f7bd2698 947\func{void}{sprintf}{\param{const char* }{ fmt}}
a660d684 948
f7bd2698 949The same as Printf.
a660d684 950
f6bcfd97
BP
951\membersection{wxString::StartsWith}\label{wxstringstartswith}
952
953\constfunc{bool}{StartsWith}{\param{const wxChar }{*prefix}, \param{wxString }{*rest = NULL}}
954
955This function can be used to test if the string starts with the specified
cc81d32f 956{\it prefix}. If it does, the function will return {\tt true} and put the rest
f6bcfd97 957of the string (i.e. after the prefix) into {\it rest} string if it is not
cc81d32f 958{\tt NULL}. Otherwise, the function returns {\tt false} and doesn't modify the
f6bcfd97
BP
959{\it rest}.
960
99f09bc1 961\membersection{wxString::Strip}\label{wxstringstrip}
a660d684
KB
962
963\begin{verbatim}
f7bd2698 964enum stripType {leading = 0x1, trailing = 0x2, both = 0x3};
a660d684
KB
965\end{verbatim}
966
f7bd2698 967\constfunc{wxString}{Strip}{\param{stripType}{ s = trailing}}
a660d684 968
f7bd2698
JS
969Strip characters at the front and/or end. The same as Trim except that it
970doesn't change this string.
a660d684 971
99f09bc1
VZ
972\membersection{wxString::SubString}\label{wxstringsubstring}
973
f6bcfd97 974\constfunc{wxString}{SubString}{\param{size\_t}{ from}, \param{size\_t}{ to}}
99f09bc1 975
b855ef77
VZ
976Deprecated, use \helpref{Mid}{wxstringmid} instead (but note that parameters
977have different meaning).
978
979Returns the part of the string between the indices {\it from} and {\it to}
980inclusive.
99f09bc1 981
6d9d6350
JS
982\membersection{wxString::ToAscii}\label{wxstringtoascii}
983
984\constfunc{const char*}{ToAscii}{\void}
985
986Converts the string to an ASCII, 7-bit string (ANSI builds only).
987
988\constfunc{const wxCharBuffer}{ToAscii}{\void}
989
990Converts the string to an ASCII, 7-bit string in the form of
991a wxCharBuffer (Unicode builds only).
992
bd8465ff
VS
993Note that this conversion only works if the string contains only ASCII
994characters. The \helpref{mb\_str}{wxstringmbstr} method provides more
995powerful means of converting wxString to C string.
996
cd0b1709
VZ
997\membersection{wxString::ToDouble}\label{wxstringtodouble}
998
f6bcfd97 999\constfunc{bool}{ToDouble}{\param{double}{ *val}}
cd0b1709 1000
cc81d32f
VS
1001Attempts to convert the string to a floating point number. Returns true on
1002success (the number is stored in the location pointed to by {\it val}) or false
cd0b1709
VZ
1003if the string does not represent such number.
1004
f6bcfd97
BP
1005\wxheading{See also}
1006
1007\helpref{wxString::ToLong}{wxstringtolong},\\
1008\helpref{wxString::ToULong}{wxstringtoulong}
1009
cd0b1709
VZ
1010\membersection{wxString::ToLong}\label{wxstringtolong}
1011
538f35cc 1012\constfunc{bool}{ToLong}{\param{long}{ *val}, \param{int }{base = $10$}}
cd0b1709 1013
4eb438cf 1014Attempts to convert the string to a signed integer in base {\it base}. Returns
cc81d32f
VS
1015{\tt true} on success in which case the number is stored in the location
1016pointed to by {\it val} or {\tt false} if the string does not represent a
4eb438cf
VZ
1017valid number in the given base.
1018
538f35cc
VZ
1019The value of {\it base} must be comprised between $2$ and $36$, inclusive, or
1020be a special value $0$ which means that the usual rules of {\tt C} numbers are
1021applied: if the number starts with {\tt 0x} it is considered to be in base
1022$16$, if it starts with {\tt 0} - in base $8$ and in base $10$ otherwise. Note
1023that you may not want to specify the base $0$ if you are parsing the numbers
1024which may have leading zeroes as they can yield unexpected (to the user not
1025familiar with C) results.
cd0b1709 1026
f6bcfd97
BP
1027\wxheading{See also}
1028
1029\helpref{wxString::ToDouble}{wxstringtodouble},\\
1030\helpref{wxString::ToULong}{wxstringtoulong}
1031
cd0b1709
VZ
1032\membersection{wxString::ToULong}\label{wxstringtoulong}
1033
538f35cc 1034\constfunc{bool}{ToULong}{\param{unsigned long}{ *val}, \param{int }{base = $10$}}
4eb438cf 1035
dbd94b75 1036Attempts to convert the string to a unsigned integer in base {\it base}.
cc81d32f
VS
1037Returns {\tt true} on success in which case the number is stored in the
1038location pointed to by {\it val} or {\tt false} if the string does not
4eb438cf 1039represent a valid number in the given base.
cd0b1709 1040
ec64d632
VZ
1041See \helpref{wxString::ToLong}{wxstringtolong} for the more detailed
1042description of the {\it base} parameter.
cd0b1709 1043
f6bcfd97
BP
1044\wxheading{See also}
1045
1046\helpref{wxString::ToDouble}{wxstringtodouble},\\
1047\helpref{wxString::ToLong}{wxstringtolong}
1048
f7bd2698 1049\membersection{wxString::Trim}\label{wxstringtrim}
a660d684 1050
cc81d32f 1051\func{wxString\&}{Trim}{\param{bool}{ fromRight = true}}
a660d684 1052
f7bd2698 1053Removes spaces from the left or from the right (default).
a660d684 1054
f7bd2698 1055\membersection{wxString::Truncate}\label{wxstringtruncate}
a660d684 1056
f7bd2698 1057\func{wxString\&}{Truncate}{\param{size\_t}{ len}}
a660d684 1058
f7bd2698 1059Truncate the string to the given length.
a660d684 1060
f7bd2698
JS
1061\membersection{wxString::UngetWriteBuf}\label{wxstringungetwritebuf}
1062
1063\func{void}{UngetWriteBuf}{\void}
1064
448025b0
VZ
1065\func{void}{UngetWriteBuf}{\param{size\_t }{len}}
1066
1067Puts the string back into a reasonable state (in which it can be used
1068normally), after
f7bd2698 1069\rtfsp\helpref{wxString::GetWriteBuf}{wxstringgetwritebuf} was called.
a660d684 1070
448025b0
VZ
1071The version of the function without the {\it len} parameter will calculate the
1072new string length itself assuming that the string is terminated by the first
1073{\tt NUL} character in it while the second one will use the specified length
1074and thus is the only version which should be used with the strings with
1075embedded {\tt NUL}s (it is also slightly more efficient as {\tt strlen()}
1076doesn't have to be called).
1077
99f09bc1
VZ
1078\membersection{wxString::Upper}\label{wxstringupper}
1079
1080\constfunc{wxString}{Upper}{\void}
1081
1082Returns this string converted to upper case.
1083
1084\membersection{wxString::UpperCase}\label{wxstringuppercase}
a660d684 1085
f7bd2698
JS
1086\func{void}{UpperCase}{\void}
1087
1088The same as MakeUpper.
a660d684 1089
bd8465ff
VS
1090\membersection{wxString::wc\_str}\label{wxstringwcstr}
1091
1092\constfunc{const wchar\_t*}{wc\_str}{\param{wxMBConv\&}{ conv}}
1093
1094\constfunc{const wxWCharBuffer}{wc\_str}{\param{wxMBConv\&}{ conv}}
1095
1096Returns wide character representation of the string.
1097In ANSI build, converts using \arg{conv}'s \helpref{cMB2WC}{wxmbconvcmb2wc}
1098method and returns wxWCharBuffer. In Unicode build, this function is same
1099as \helpref{c\_str}{wxstringcstr}.
1100The macro wxWX2WCbuf is defined as the correct return type (without const).
1101
1102\wxheading{See also}
1103
1104\helpref{wxMBConv}{wxmbconv},
1105\helpref{c\_str}{wxstringcstr}, \helpref{mb\_str}{wxstringwcstr},
1106\helpref{fn\_str}{wxstringfnstr}
1107
99f09bc1
VZ
1108\membersection{wxString::operator!}\label{wxstringoperatornot}
1109
1110\constfunc{bool}{operator!}{\void}
1111
cc81d32f 1112Empty string is false, so !string will only return true if the string is empty.
dbd94b75 1113This allows the tests for NULLness of a {\it const char *} pointer and emptiness
99f09bc1
VZ
1114of the string to look the same in the code and makes it easier to port old code
1115to wxString.
1116
1117See also \helpref{IsEmpty()}{wxstringisempty}.
1118
a660d684
KB
1119\membersection{wxString::operator $=$}\label{wxstringoperatorassign}
1120
f7bd2698
JS
1121\func{wxString\&}{operator $=$}{\param{const wxString\&}{ str}}
1122
1123\func{wxString\&}{operator $=$}{\param{const char*}{ psz}}
1124
1125\func{wxString\&}{operator $=$}{\param{char}{ c}}
1126
1127\func{wxString\&}{operator $=$}{\param{const unsigned char*}{ psz}}
1128
1129\func{wxString\&}{operator $=$}{\param{const wchar\_t*}{ pwz}}
a660d684 1130
99f09bc1
VZ
1131Assignment: the effect of each operation is the same as for the corresponding
1132constructor (see \helpref{wxString constructors}{wxstringconstruct}).
5de76427 1133
f6bcfd97 1134\membersection{wxString::operator $+$}\label{wxstringoperatorplus}
5de76427 1135
dbd94b75
KH
1136Concatenation: all these operators return a new string equal to the
1137concatenation of the operands.
5de76427
JS
1138
1139\func{wxString}{operator $+$}{\param{const wxString\&}{ x}, \param{const wxString\&}{ y}}
1140
1141\func{wxString}{operator $+$}{\param{const wxString\&}{ x}, \param{const char*}{ y}}
1142
1143\func{wxString}{operator $+$}{\param{const wxString\&}{ x}, \param{char}{ y}}
1144
1145\func{wxString}{operator $+$}{\param{const char*}{ x}, \param{const wxString\&}{ y}}
1146
99f09bc1 1147\membersection{wxString::operator $+=$}\label{wxstringplusequal}
a660d684 1148
f7bd2698
JS
1149\func{void}{operator $+=$}{\param{const wxString\&}{ str}}
1150
1151\func{void}{operator $+=$}{\param{const char*}{ psz}}
1152
1153\func{void}{operator $+=$}{\param{char}{ c}}
a660d684 1154
99f09bc1 1155Concatenation in place: the argument is appended to the string.
a660d684
KB
1156
1157\membersection{wxString::operator []}\label{wxstringoperatorbracket}
1158
f7bd2698
JS
1159\func{char\&}{operator []}{\param{size\_t}{ i}}
1160
1161\func{char}{operator []}{\param{size\_t}{ i}}
1162
1163\func{char}{operator []}{\param{int}{ i}}
a660d684
KB
1164
1165Element extraction.
1166
1167\membersection{wxString::operator ()}\label{wxstringoperatorparenth}
1168
f7bd2698
JS
1169\func{wxString}{operator ()}{\param{size\_t}{ start}, \param{size\_t}{ len}}
1170
1171Same as Mid (substring extraction).
a660d684
KB
1172
1173\membersection{wxString::operator \cinsert}\label{wxstringoperatorout}
f7bd2698 1174
037267e1 1175\func{wxString\&}{operator \cinsert}{\param{const wxString\&}{ str}}
f7bd2698 1176
037267e1 1177\func{wxString\&}{operator \cinsert}{\param{const char*}{ psz}}
f7bd2698 1178
037267e1 1179\func{wxString\&}{operator \cinsert}{\param{char }{ch}}
f7bd2698
JS
1180
1181Same as $+=$.
a660d684 1182
99f09bc1
VZ
1183\func{wxString\&}{operator \cinsert}{\param{int}{ i}}
1184
1185\func{wxString\&}{operator \cinsert}{\param{float}{ f}}
1186
1187\func{wxString\&}{operator \cinsert}{\param{double}{ d}}
1188
1189These functions work as C++ stream insertion operators: they insert the given
1190value into the string. Precision or format cannot be set using them, you can use
1191\helpref{Printf}{wxstringprintf} for this.
1192
a660d684 1193\membersection{wxString::operator \cextract}\label{wxstringoperatorin}
a660d684 1194
f7bd2698 1195\func{friend istream\&}{operator \cextract}{\param{istream\&}{ is}, \param{wxString\&}{ str}}
a660d684 1196
f7bd2698 1197Extraction from a stream.
a660d684 1198
f7bd2698 1199\membersection{wxString::operator const char*}\label{wxstringoperatorconstcharpt}
a660d684 1200
f7bd2698 1201\constfunc{}{operator const char*}{\void}
a660d684 1202
f7bd2698 1203Implicit conversion to a C string.
a660d684 1204
99f09bc1 1205\membersection{Comparison operators}\label{wxstringcomparison}
a660d684 1206
f7bd2698 1207\func{bool}{operator $==$}{\param{const wxString\&}{ x}, \param{const wxString\&}{ y}}
a660d684 1208
f7bd2698 1209\func{bool}{operator $==$}{\param{const wxString\&}{ x}, \param{const char*}{ t}}
a660d684 1210
f7bd2698 1211\func{bool}{operator $!=$}{\param{const wxString\&}{ x}, \param{const wxString\&}{ y}}
a660d684 1212
f7bd2698 1213\func{bool}{operator $!=$}{\param{const wxString\&}{ x}, \param{const char*}{ t}}
a660d684 1214
f7bd2698 1215\func{bool}{operator $>$}{\param{const wxString\&}{ x}, \param{const wxString\&}{ y}}
a660d684 1216
f7bd2698 1217\func{bool}{operator $>$}{\param{const wxString\&}{ x}, \param{const char*}{ t}}
a660d684 1218
f7bd2698 1219\func{bool}{operator $>=$}{\param{const wxString\&}{ x}, \param{const wxString\&}{ y}}
a660d684 1220
f7bd2698 1221\func{bool}{operator $>=$}{\param{const wxString\&}{ x}, \param{const char*}{ t}}
a660d684 1222
f7bd2698 1223\func{bool}{operator $<$}{\param{const wxString\&}{ x}, \param{const wxString\&}{ y}}
a660d684 1224
f7bd2698 1225\func{bool}{operator $<$}{\param{const wxString\&}{ x}, \param{const char*}{ t}}
a660d684 1226
f7bd2698 1227\func{bool}{operator $<=$}{\param{const wxString\&}{ x}, \param{const wxString\&}{ y}}
a660d684 1228
f7bd2698 1229\func{bool}{operator $<=$}{\param{const wxString\&}{ x}, \param{const char*}{ t}}
a660d684 1230
f7bd2698 1231\wxheading{Remarks}
a660d684 1232
f7bd2698 1233These comparisons are case-sensitive.
a660d684 1234
1d218550
VZ
1235
1236\section{\class{wxStringBuffer}}\label{wxstringbuffer}
1237
1238This tiny class allows to conveniently access the \helpref{wxString}{wxstring}
dbd94b75 1239internal buffer as a writable pointer without any risk of forgetting to restore
1d218550
VZ
1240the string to the usable state later.
1241
1242For example, assuming you have a low-level OS function called
1243{\tt GetMeaningOfLifeAsString(char *)} returning the value in the provided
1244buffer (which must be writable, of course) you might call it like this:
1245
1246\begin{verbatim}
1247 wxString theAnswer;
1248 GetMeaningOfLifeAsString(wxStringBuffer(theAnswer, 1024));
1249 if ( theAnswer != "42" )
1250 {
1251 wxLogError("Something is very wrong!");
1252 }
1253\end{verbatim}
1254
5687a67c
RN
1255Note that the exact usage of this depends on whether on not wxUSE\_STL is enabled. If
1256wxUSE\_STL is enabled, wxStringBuffer creates a seperate empty character buffer, and
1257if wxUSE\_STL is disabled, it uses GetWriteBuf() from wxString, keeping the same buffer
1258wxString uses intact. In other words, relying on wxStringBuffer containing the old
1259wxString data is probably not a good idea if you want to build your program in both
1260with and without wxUSE\_STL.
1261
1d218550
VZ
1262\wxheading{Derived from}
1263
1264None
1265
1266\wxheading{Include files}
1267
1268<wx/string.h>
1269
1270\latexignore{\rtfignore{\wxheading{Members}}}
1271
08f1d438 1272\membersection{wxStringBuffer::wxStringBuffer}\label{wxstringbufferctor}
1d218550
VZ
1273
1274\func{}{wxStringBuffer}{\param{const wxString\& }{str}, \param{size\_t }{len}}
1275
1276Constructs a writable string buffer object associated with the given string
2edb0bde 1277and containing enough space for at least {\it len} characters. Basically, this
1d218550
VZ
1278is equivalent to calling \helpref{GetWriteBuf}{wxstringgetwritebuf} and
1279saving the result.
1280
08f1d438 1281\membersection{wxStringBuffer::\destruct{wxStringBuffer}}\label{wxstringbufferdtor}
1d218550
VZ
1282
1283\func{}{\destruct{wxStringBuffer}}{\void}
1284
1285Restores the string passed to the constructor to the usable state by calling
1286\helpref{UngetWriteBuf}{wxstringungetwritebuf} on it.
1287
08f1d438 1288\membersection{wxStringBuffer::operator wxChar *}\label{wxstringbufferwxchar}
1d218550 1289
c298ea48
RN
1290\func{wxChar *}{operator wxChar *}{\void}
1291
1292Returns the writable pointer to a buffer of the size at least equal to the
1293length specified in the constructor.
1294
1295
1296
1297\section{\class{wxStringBufferLength}}\label{wxstringbufferlength}
1298
1299This tiny class allows to conveniently access the \helpref{wxString}{wxstring}
1300internal buffer as a writable pointer without any risk of forgetting to restore
1301the string to the usable state later, and allows the user to set the internal
1302length of the string.
1303
1304For example, assuming you have a low-level OS function called
1305{\tt int GetMeaningOfLifeAsString(char *)} copying the value in the provided
1306buffer (which must be writable, of course), and returning the actual length
1307of the string, you might call it like this:
1308
1309\begin{verbatim}
1310 wxString theAnswer;
1311 wxStringBuffer theAnswerBuffer(theAnswer, 1024);
1312 int nLength = GetMeaningOfLifeAsString(theAnswerBuffer);
1313 theAnswerBuffer.SetLength(nLength);
1314 if ( theAnswer != "42" )
1315 {
1316 wxLogError("Something is very wrong!");
1317 }
1318\end{verbatim}
1319
5687a67c
RN
1320Note that the exact usage of this depends on whether on not wxUSE\_STL is enabled. If
1321wxUSE\_STL is enabled, wxStringBuffer creates a seperate empty character buffer, and
1322if wxUSE\_STL is disabled, it uses GetWriteBuf() from wxString, keeping the same buffer
1323wxString uses intact. In other words, relying on wxStringBuffer containing the old
1324wxString data is probably not a good idea if you want to build your program in both
1325with and without wxUSE\_STL.
1326
c298ea48
RN
1327Note that SetLength {\tt must} be called before wxStringBufferLength destructs.
1328
1329\wxheading{Derived from}
1330
1331None
1332
1333\wxheading{Include files}
1334
1335<wx/string.h>
1336
1337\latexignore{\rtfignore{\wxheading{Members}}}
1338
1339\membersection{wxStringBufferLength::wxStringBufferLength}\label{wxstringbufferlengthctor}
1340
1341\func{}{wxStringBuffer}{\param{const wxString\& }{str}, \param{size\_t }{len}}
1342
1343Constructs a writable string buffer object associated with the given string
1344and containing enough space for at least {\it len} characters. Basically, this
1345is equivalent to calling \helpref{GetWriteBuf}{wxstringgetwritebuf} and
1346saving the result.
1347
1348\membersection{wxStringBufferLength::\destruct{wxStringBufferLength}}\label{wxstringbufferlengthdtor}
1349
1350\func{}{\destruct{wxStringBufferLength}}{\void}
1351
1352Restores the string passed to the constructor to the usable state by calling
1353\helpref{UngetWriteBuf}{wxstringungetwritebuf} on it.
1354
1355\membersection{wxStringBufferLength::SetLength}\label{wxstringbufferlengthsetlength}
1356
1357\func{void}{SetLength}{\param{size\_t }{nLength}}
1358
1359Sets the internal length of the string referred to by wxStringBufferLength to
1360{\it nLength} characters.
1361
1362Must be called before wxStringBufferLength destructs.
1363
1364\membersection{wxStringBufferLength::operator wxChar *}\label{wxstringbufferlengthwxchar}
1365
1366\func{wxChar *}{operator wxChar *}{\void}
1d218550
VZ
1367
1368Returns the writable pointer to a buffer of the size at least equal to the
1369length specified in the constructor.
1370
1371