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