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