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