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