]> git.saurik.com Git - wxWidgets.git/blob - docs/latex/wx/wxstring.tex
Some doc updates,
[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.
10
11 \wxheading{Derived from}
12
13 None
14
15 \wxheading{Include files}
16
17 <wx/string.h>
18
19 \wxheading{Predefined objects}
20
21 Objects:
22
23 {\bf wxEmptyString}
24
25 \wxheading{See also}
26
27 \overview{Overview}{wxstringoverview}
28
29 \latexignore{\rtfignore{\wxheading{Function groups}}}
30
31 \membersection{Constructors and assignment operators}
32
33 A strign may be constructed either from a C string, (some number of copies of)
34 a single character or a wide (UNICODE) string. For all constructors (except the
35 default which creates an empty string) there is also a corresponding assignment
36 operator.
37
38 \helpref{wxString}{wxstringconstruct}\\
39 \helpref{operator $=$}{wxstringoperatorassign}\\
40 \helpref{\destruct{wxString}}{wxstringdestruct}
41
42 \membersection{String length}
43
44 These functions return the string length and check whether the string is empty
45 or empty it.
46
47 \helpref{Len}{wxstringlen}\\
48 \helpref{IsEmpty}{wxstringisempty}\\
49 \helpref{operator!}{wxstringoperatornot}\\
50 \helpref{Empty}{wxstringempty}\\
51 \helpref{Clear}{wxstringclear}
52
53 \membersection{Character access}
54
55 Many functions in this section take a character index in the string. As with C
56 strings and/or arrays, the indices start from $0$, so the first character of a
57 string is string[$0$]. Attempt to access a character beyond the end of the
58 string (which may be even $0$ if the string is empty) will provocate an assert
59 failure in \helpref{debug build}{debuggingoverview}, but no checks are done in
60 release builds.
61
62 This section also contains both implicit and explicit conversions to C style
63 strings. Although implicit conversion is quite convenient, it is advised to use
64 explicit \helpref{c\_str()}{wxstringcstr} method for the sake of clarity. Also
65 see \helpref{overview}{wxstringadvices} for the cases where it is necessary to
66 use it.
67
68 \helpref{GetChar}{wxstringgetchar}\\
69 \helpref{GetWritableChar}{wxstringgetwritablechar}\\
70 \helpref{SetChar}{wxstringsetchar}\\
71 \helpref{Last}{wxstringlast}\\
72 \helpref{operator []}{wxstringoperatorbracket}\\
73 \helpref{c\_str}{wxstringcstr}\\
74 \helpref{operator const char*}{wxstringoperatorconstcharpt}
75
76 \membersection{Concatenation}
77
78 Anything may be concatenated (appended to) with a string. However, you can't
79 append something to a C string (including literal constants), so to do this it
80 should be converted to a wxString first.
81
82 \helpref{operator \cinsert}{wxstringoperatorout}\\
83 \helpref{operator $+=$}{wxstringplusequal}\\
84 \helpref{operator $+$}{wxstringoperatorplus}\\
85 \helpref{Append}{wxstringappend}\\
86 \helpref{Prepend}{wxstringprepend}
87
88 \membersection{Comparison}
89
90 The default comparison function \helpref{Cmp}{wxstringcmp} is case-sensitive and
91 so is the default version of \helpref{IsSameAs}{wxstringissameas}. For case
92 insensitive comparisons you should use \helpref{CmpNoCase}{wxstringcmpnocase} or
93 give a second parameter to IsSameAs. This last function is may be more
94 convenient if only equality of the strings matters because it returns a boolean
95 true value if the strings are the same and not 0 (which is usually FALSE in C)
96 as Cmp does.
97
98 \helpref{Matches}{wxstringmatches} is a poor man's regular expression matcher:
99 it only understands '*' and '?' metacharacters in the sense of DOS command line
100 interpreter.
101
102 \helpref{Cmp}{wxstringcmp}\\
103 \helpref{CmpNoCase}{wxstringcmpnocase}\\
104 \helpref{IsSameAs}{wxstringissameas}\\
105 \helpref{Matches}{wxstringmatches}
106
107 \membersection{Substring extraction}
108
109 These functions allow to extract substring from this string. All of them don't
110 modify the original string and return a new string containing the extracted
111 substring.
112
113 \helpref{Mid}{wxstringmid}\\
114 \helpref{operator()}{wxstringoperatorparenth}\\
115 \helpref{Left}{wxstringleft}\\
116 \helpref{Right}{wxstringright}\\
117 \helpref{BeforeFirst}{wxstringbeforefirst}\\
118 \helpref{BeforeLast}{wxstringbeforelast}\\
119 \helpref{AfterFirst}{wxstringafterfirst}\\
120 \helpref{AfterLast}{wxstringafterlast}
121
122 \membersection{Case conversion}
123
124 The MakeXXX() variants modify the string in place, while the other functions
125 return a new string which containts the original text converted to the upper or
126 lower case and leave the original string unchanged.
127
128 \helpref{MakeUpper}{wxstringmakeupper}\\
129 \helpref{Upper}{wxstringupper}\\
130 \helpref{MakeLower}{wxstringmakelower}\\
131 \helpref{Lower}{wxstringlower}
132
133 \membersection{Searching and replacing}
134
135 These functions replace the standard {\it strchr()} and {\it strstr()}
136 functions.
137
138 \helpref{Find}{wxstringfind}\\
139 \helpref{Replace}{wxstringreplace}
140
141 \membersection{Conversion to numbers}
142
143 The string provides functions for conversion to signed and unsigned integer and
144 floating point numbers. All three functions take a pointer to the variable to
145 put the numeric value in and return TRUE if the {\bf entire} string could be
146 converted to a number.
147
148 \helpref{ToLong}{wxstringtolong}\\
149 \helpref{ToULong}{wxstringtoulong}\\
150 \helpref{ToDouble}{wxstringtodouble}
151
152 \membersection{Writing values into the string}
153
154 Both formatted versions (\helpref{Printf}{wxstringprintf}) and stream-like
155 insertion operators exist (for basic types only). Additionally, the
156 \helpref{Format}{wxstringformat} function allows to use simply append
157 formatted value to a string:
158
159 \begin{verbatim}
160 // the following 2 snippets are equivalent
161
162 wxString s = "...";
163 s += wxString::Format("%d", n);
164
165 wxString s;
166 s.Printf("...%d", n);
167 \end{verbatim}
168
169 \helpref{Format}{wxstringformat}\\
170 \helpref{FormatV}{wxstringformatv}\\
171 \helpref{Printf}{wxstringprintf}\\
172 \helpref{PrintfV}{wxstringprintfv}\\
173 \helpref{operator \cinsert}{wxstringoperatorout}
174
175 \membersection{Memory management}
176
177 These are "advanced" functions and they will be needed quite rarily.
178 \helpref{Alloc}{wxstringalloc} and \helpref{Shrink}{wxstringshrink} are only
179 interesting for optimization purposes.
180 \helpref{GetWriteBuf}{wxstringgetwritebuf} may be very useful when working with
181 some external API which requires the caller to provide a writable buffer, but
182 extreme care should be taken when using it: before performing any other
183 operation on the string \helpref{UngetWriteBuf}{wxstringungetwritebuf} {\bf
184 must} be called!
185
186 \helpref{Alloc}{wxstringalloc}\\
187 \helpref{Shrink}{wxstringshrink}\\
188 \helpref{GetWriteBuf}{wxstringgetwritebuf}\\
189 \helpref{UngetWriteBuf}{wxstringungetwritebuf}
190
191 \membersection{Miscellaneous}
192
193 Other string functions.
194
195 \helpref{Trim}{wxstringtrim}\\
196 \helpref{Pad}{wxstringpad}\\
197 \helpref{Truncate}{wxstringtruncate}
198
199 \membersection{wxWindows 1.xx compatiblity functions}
200
201 These functiosn are deprecated, please consider using new wxWindows 2.0
202 functions instead of them (or, even better, std::string compatible variants).
203
204 \helpref{SubString}{wxstringsubstring}\\
205 \helpref{sprintf}{wxstringsprintf}\\
206 \helpref{CompareTo}{wxstringcompareto}\\
207 \helpref{Length}{wxstringlength}\\
208 \helpref{Freq}{wxstringfreq}\\
209 \helpref{LowerCase}{wxstringlowercase}\\
210 \helpref{UpperCase}{wxstringuppercase}\\
211 \helpref{Strip}{wxstringstrip}\\
212 \helpref{Index}{wxstringindex}\\
213 \helpref{Remove}{wxstringremove}\\
214 \helpref{First}{wxstringfirst}\\
215 \helpref{Last}{wxstringlast}\\
216 \helpref{Contains}{wxstringcontains}\\
217 \helpref{IsNull}{wxstringisnull}\\
218 \helpref{IsAscii}{wxstringisascii}\\
219 \helpref{IsNumber}{wxstringisnumber}\\
220 \helpref{IsWord}{wxstringisword}
221
222 \membersection{std::string compatibility functions}\label{wxstringat}
223
224 The supported functions are only listed here, please see any STL reference for
225 their documentation.
226
227 \begin{verbatim}
228 // take nLen chars starting at nPos
229 wxString(const wxString& str, size_t nPos, size_t nLen);
230 // take all characters from pStart to pEnd (poor man's iterators)
231 wxString(const void *pStart, const void *pEnd);
232
233 // lib.string.capacity
234 // return the length of the string
235 size_t size() const;
236 // return the length of the string
237 size_t length() const;
238 // return the maximum size of the string
239 size_t max_size() const;
240 // resize the string, filling the space with c if c != 0
241 void resize(size_t nSize, char ch = '\0');
242 // delete the contents of the string
243 void clear();
244 // returns true if the string is empty
245 bool empty() const;
246
247 // lib.string.access
248 // return the character at position n
249 char at(size_t n) const;
250 // returns the writable character at position n
251 char& at(size_t n);
252
253 // lib.string.modifiers
254 // append a string
255 wxString& append(const wxString& str);
256 // append elements str[pos], ..., str[pos+n]
257 wxString& append(const wxString& str, size_t pos, size_t n);
258 // append first n (or all if n == npos) characters of sz
259 wxString& append(const char *sz, size_t n = npos);
260
261 // append n copies of ch
262 wxString& append(size_t n, char ch);
263
264 // same as `this_string = str'
265 wxString& assign(const wxString& str);
266 // same as ` = str[pos..pos + n]
267 wxString& assign(const wxString& str, size_t pos, size_t n);
268 // same as `= first n (or all if n == npos) characters of sz'
269 wxString& assign(const char *sz, size_t n = npos);
270 // same as `= n copies of ch'
271 wxString& assign(size_t n, char ch);
272
273 // insert another string
274 wxString& insert(size_t nPos, const wxString& str);
275 // insert n chars of str starting at nStart (in str)
276 wxString& insert(size_t nPos, const wxString& str, size_t nStart, size_t n);
277
278 // insert first n (or all if n == npos) characters of sz
279 wxString& insert(size_t nPos, const char *sz, size_t n = npos);
280 // insert n copies of ch
281 wxString& insert(size_t nPos, size_t n, char ch);
282
283 // delete characters from nStart to nStart + nLen
284 wxString& erase(size_t nStart = 0, size_t nLen = npos);
285
286 // replaces the substring of length nLen starting at nStart
287 wxString& replace(size_t nStart, size_t nLen, const char* sz);
288 // replaces the substring with nCount copies of ch
289 wxString& replace(size_t nStart, size_t nLen, size_t nCount, char ch);
290 // replaces a substring with another substring
291 wxString& replace(size_t nStart, size_t nLen,
292 const wxString& str, size_t nStart2, size_t nLen2);
293 // replaces the substring with first nCount chars of sz
294 wxString& replace(size_t nStart, size_t nLen,
295 const char* sz, size_t nCount);
296
297 // swap two strings
298 void swap(wxString& str);
299
300 // All find() functions take the nStart argument which specifies the
301 // position to start the search on, the default value is 0. All functions
302 // return npos if there were no match.
303
304 // find a substring
305 size_t find(const wxString& str, size_t nStart = 0) const;
306
307 // find first n characters of sz
308 size_t find(const char* sz, size_t nStart = 0, size_t n = npos) const;
309
310 // find the first occurence of character ch after nStart
311 size_t find(char ch, size_t nStart = 0) const;
312
313 // rfind() family is exactly like find() but works right to left
314
315 // as find, but from the end
316 size_t rfind(const wxString& str, size_t nStart = npos) const;
317
318 // as find, but from the end
319 size_t rfind(const char* sz, size_t nStart = npos,
320 size_t n = npos) const;
321 // as find, but from the end
322 size_t rfind(char ch, size_t nStart = npos) const;
323
324 // find first/last occurence of any character in the set
325
326 //
327 size_t find_first_of(const wxString& str, size_t nStart = 0) const;
328 //
329 size_t find_first_of(const char* sz, size_t nStart = 0) const;
330 // same as find(char, size_t)
331 size_t find_first_of(char c, size_t nStart = 0) const;
332 //
333 size_t find_last_of (const wxString& str, size_t nStart = npos) const;
334 //
335 size_t find_last_of (const char* s, size_t nStart = npos) const;
336 // same as rfind(char, size_t)
337 size_t find_last_of (char c, size_t nStart = npos) const;
338
339 // find first/last occurence of any character not in the set
340
341 //
342 size_t find_first_not_of(const wxString& str, size_t nStart = 0) const;
343 //
344 size_t find_first_not_of(const char* s, size_t nStart = 0) const;
345 //
346 size_t find_first_not_of(char ch, size_t nStart = 0) const;
347 //
348 size_t find_last_not_of(const wxString& str, size_t nStart=npos) const;
349 //
350 size_t find_last_not_of(const char* s, size_t nStart = npos) const;
351 //
352 size_t find_last_not_of(char ch, size_t nStart = npos) const;
353
354 // All compare functions return a negative, zero or positive value
355 // if the [sub]string is less, equal or greater than the compare() argument.
356
357 // just like strcmp()
358 int compare(const wxString& str) const;
359 // comparison with a substring
360 int compare(size_t nStart, size_t nLen, const wxString& str) const;
361 // comparison of 2 substrings
362 int compare(size_t nStart, size_t nLen,
363 const wxString& str, size_t nStart2, size_t nLen2) const;
364 // just like strcmp()
365 int compare(const char* sz) const;
366 // substring comparison with first nCount characters of sz
367 int compare(size_t nStart, size_t nLen,
368 const char* sz, size_t nCount = npos) const;
369
370 // substring extraction
371 wxString substr(size_t nStart = 0, size_t nLen = npos) const;
372 \end{verbatim}
373
374 %%%%% MEMBERS HERE %%%%%
375 \helponly{\insertatlevel{2}{
376
377 \wxheading{Members}
378
379 }}
380
381 \membersection{wxString::wxString}\label{wxstringconstruct}
382
383 \func{}{wxString}{\void}
384
385 Default constructor.
386
387 \func{}{wxString}{\param{const wxString\&}{ x}}
388
389 Copy constructor.
390
391 \func{}{wxString}{\param{char}{ ch}, \param{size\_t}{ n = 1}}
392
393 Constructs a string of {\it n} copies of character {\it ch}.
394
395 \func{}{wxString}{\param{const char*}{ psz}, \param{size\_t}{ nLength = wxSTRING\_MAXLEN}}
396
397 Takes first {\it nLength} characters from the C string {\it psz}.
398 The default value of wxSTRING\_MAXLEN means take all the string.
399
400 \func{}{wxString}{\param{const unsigned char*}{ psz}, \param{size\_t}{ nLength = wxSTRING\_MAXLEN}}
401
402 For compilers using unsigned char: takes first {\it nLength} characters from the C string {\it psz}.
403 The default value of wxSTRING\_MAXLEN means take all the string.
404
405 \func{}{wxString}{\param{const wchar\_t*}{ psz}}
406
407 Constructs a string from the wide (UNICODE) string.
408
409 \membersection{wxString::\destruct{wxString}}\label{wxstringdestruct}
410
411 \func{}{\destruct{wxString}}{\void}
412
413 String destructor. Note that this is not virtual, so wxString must not be inherited from.
414
415 \membersection{wxString::Alloc}\label{wxstringalloc}
416
417 \func{void}{Alloc}{\param{size\_t}{ nLen}}
418
419 Preallocate enough space for wxString to store {\it nLen} characters. This function
420 may be used to increase speed when the string is constructed by repeated
421 concatenation as in
422
423 \begin{verbatim}
424
425 // delete all vowels from the string
426 wxString DeleteAllVowels(const wxString& original)
427 {
428 wxString result;
429
430 size_t len = original.length();
431
432 result.Alloc(len);
433
434 for ( size_t n = 0; n < len; n++ )
435 {
436 if ( strchr("aeuio", tolower(original[n])) == NULL )
437 result += original[n];
438 }
439
440 return result;
441 }
442
443 \end{verbatim}
444
445 because it will avoid the need of reallocating string memory many times (in case
446 of long strings). Note that it does not set the maximal length of a string - it
447 will still expand if more than {\it nLen} characters are stored in it. Also, it
448 does not truncate the existing string (use
449 \helpref{Truncate()}{wxstringtruncate} for this) even if its current length is
450 greater than {\it nLen}
451
452 \membersection{wxString::Append}\label{wxstringappend}
453
454 \func{wxString\&}{Append}{\param{const char*}{ psz}}
455
456 Concatenates {\it psz} to this string, returning a reference to it.
457
458 \func{wxString\&}{Append}{\param{char}{ ch}, \param{int}{ count = 1}}
459
460 Concatenates character {\it ch} to this string, {\it count} times, returning a reference
461 to it.
462
463 \membersection{wxString::AfterFirst}\label{wxstringafterfirst}
464
465 \constfunc{wxString}{AfterFirst}{\param{char}{ ch}}
466
467 Gets all the characters after the first occurence of {\it ch}.
468 Returns the empty string if {\it ch} is not found.
469
470 \membersection{wxString::AfterLast}\label{wxstringafterlast}
471
472 \constfunc{wxString}{AfterLast}{\param{char}{ ch}}
473
474 Gets all the characters after the last occurence of {\it ch}.
475 Returns the whole string if {\it ch} is not found.
476
477 \membersection{wxString::BeforeFirst}\label{wxstringbeforefirst}
478
479 \constfunc{wxString}{BeforeFirst}{\param{char}{ ch}}
480
481 Gets all characters before the first occurence of {\it ch}.
482 Returns the whole string if {\it ch} is not found.
483
484 \membersection{wxString::BeforeLast}\label{wxstringbeforelast}
485
486 \constfunc{wxString}{BeforeLast}{\param{char}{ ch}}
487
488 Gets all characters before the last occurence of {\it ch}.
489 Returns the empty string if {\it ch} is not found.
490
491 \membersection{wxString::c\_str}\label{wxstringcstr}
492
493 \constfunc{const char *}{c\_str}{\void}
494
495 Returns a pointer to the string data.
496
497 \membersection{wxString::Clear}\label{wxstringclear}
498
499 \func{void}{Clear}{\void}
500
501 Empties the string and frees memory occupied by it.
502
503 See also: \helpref{Empty}{wxstringempty}
504
505 \membersection{wxString::Cmp}\label{wxstringcmp}
506
507 \constfunc{int}{Cmp}{\param{const char*}{ psz}}
508
509 Case-sensitive comparison.
510
511 Returns a positive value if the string is greater than the argument, zero if
512 it si equal to it or negative value if it is less than argument (same semantics
513 as the standard {\it strcmp()} function).
514
515 See also \helpref{CmpNoCase}{wxstringcmpnocase}, \helpref{IsSameAs}{wxstringissameas}.
516
517 \membersection{wxString::CmpNoCase}\label{wxstringcmpnocase}
518
519 \constfunc{int}{CmpNoCase}{\param{const char*}{ psz}}
520
521 Case-insensitive comparison.
522
523 Returns a positive value if the string is greater than the argument, zero if
524 it si equal to it or negative value if it is less than argument (same semantics
525 as the standard {\it strcmp()} function).
526
527 See also \helpref{Cmp}{wxstringcmp}, \helpref{IsSameAs}{wxstringissameas}.
528
529 \membersection{wxString::CompareTo}\label{wxstringcompareto}
530
531 \begin{verbatim}
532 #define NO_POS ((int)(-1)) // undefined position
533 enum caseCompare {exact, ignoreCase};
534 \end{verbatim}
535
536 \constfunc{int}{CompareTo}{\param{const char*}{ psz}, \param{caseCompare}{ cmp = exact}}
537
538 Case-sensitive comparison. Returns 0 if equal, 1 if greater or -1 if less.
539
540 \membersection{wxString::Contains}\label{wxstringcontains}
541
542 \constfunc{bool}{Contains}{\param{const wxString\&}{ str}}
543
544 Returns 1 if target appears anyhere in wxString; else 0.
545
546 \membersection{wxString::Empty}\label{wxstringempty}
547
548 \func{void}{Empty}{\void}
549
550 Makes the string empty, but doesn't free memory occupied by the string.
551
552 See also: \helpref{Clear()}{wxstringclear}.
553
554 \membersection{wxString::Find}\label{wxstringfind}
555
556 \constfunc{int}{Find}{\param{char}{ ch}, \param{bool}{ fromEnd = FALSE}}
557
558 Searches for the given character. Returns the starting index, or -1 if not found.
559
560 \constfunc{int}{Find}{\param{const char*}{ sz}}
561
562 Searches for the given string. Returns the starting index, or -1 if not found.
563
564 \membersection{wxString::First}\label{wxstringfirst}
565
566 \func{size\_t}{First}{\param{char}{ c}}
567
568 \constfunc{size\_t}{First}{\param{const char*}{ psz}}
569
570 \constfunc{size\_t}{First}{\param{const wxString\&}{ str}}
571
572 \constfunc{size\_t}{First}{\param{const char}{ ch}}
573
574 Returns the first occurrence of the item.
575
576 \membersection{wxString::Format}\label{wxstringformat}
577
578 \func{static wxString}{Format}{\param{const wxChar }{*format}, \param{}{...}}
579
580 This static function returns the string containing the result of calling
581 \helpref{Printf}{wxstringprintf} with the passed parameters on it.
582
583 \wxheading{See also}
584
585 \helpref{FormatV}{wxstringformatv}, \helpref{Printf}{wxstringprintf}
586
587 \membersection{wxString::FormatV}\label{wxstringformatv}
588
589 \func{static wxString}{Format}{\param{const wxChar }{*format}, \param{va\_list }{argptr}}
590
591 This static function returns the string containing the result of calling
592 \helpref{PrintfV}{wxstringprintfv} with the passed parameters on it.
593
594 \wxheading{See also}
595
596 \helpref{Format}{wxstringformat}, \helpref{PrintfV}{wxstringprintfv}
597
598 \membersection{wxString::Freq}\label{wxstringfreq}
599
600 \constfunc{int}{Frec}{\param{char }{ch}}
601
602 Returns the number of occurences of {it ch} in the string.
603
604 \membersection{wxString::GetChar}\label{wxstringgetchar}
605
606 \constfunc{char}{GetChar}{\param{size\_t}{ n}}
607
608 Returns the character at position {\it n} (read-only).
609
610 \membersection{wxString::GetData}\label{wxstringgetdata}
611
612 \constfunc{const char*}{GetData}{\void}
613
614 wxWindows compatibility conversion. Returns a constant pointer to the data in the string.
615
616 \membersection{wxString::GetWritableChar}\label{wxstringgetwritablechar}
617
618 \func{char\&}{GetWritableChar}{\param{size\_t}{ n}}
619
620 Returns a reference to the character at position {\it n}.
621
622 \membersection{wxString::GetWriteBuf}\label{wxstringgetwritebuf}
623
624 \func{char*}{GetWriteBuf}{\param{size\_t}{ len}}
625
626 Returns a writable buffer of at least {\it len} bytes.
627
628 Call \helpref{wxString::UngetWriteBuf}{wxstringungetwritebuf} as soon as possible
629 to put the string back into a reasonable state.
630
631 \membersection{wxString::Index}\label{wxstringindex}
632
633 \constfunc{size\_t}{Index}{\param{char}{ ch}, \param{int}{ startpos = 0}}
634
635 Same as \helpref{wxString::Find}{wxstringfind}.
636
637 \constfunc{size\_t}{Index}{\param{const char*}{ sz}}
638
639 Same as \helpref{wxString::Find}{wxstringfind}.
640
641 \constfunc{size\_t}{Index}{\param{const char*}{ sz}, \param{bool}{ caseSensitive = TRUE}, \param{bool}{ fromEnd = FALSE}}
642
643 Search the element in the array, starting from either side.
644
645 If {\it fromEnd} is TRUE, reverse search direction.
646
647 If {\bf caseSensitive}, comparison is case sensitive (the default).
648
649 Returns the index of the first item matched, or NOT\_FOUND.
650
651 % TODO
652 %\membersection{wxString::insert}\label{wxstringinsert}
653 % Wrong!
654 %\func{void}{insert}{\param{const wxString\&}{ str}, \param{size\_t}{ index}}
655 %
656 %Add new element at the given position.
657 %
658 \membersection{wxString::IsAscii}\label{wxstringisascii}
659
660 \constfunc{bool}{IsAscii}{\void}
661
662 Returns TRUE if the string is ASCII.
663
664 \membersection{wxString::IsEmpty}\label{wxstringisempty}
665
666 \constfunc{bool}{IsEmpty}{\void}
667
668 Returns TRUE if the string is NULL.
669
670 \membersection{wxString::IsNull}\label{wxstringisnull}
671
672 \constfunc{bool}{IsNull}{\void}
673
674 Returns TRUE if the string is NULL (same as IsEmpty).
675
676 \membersection{wxString::IsNumber}\label{wxstringisnumber}
677
678 \constfunc{bool}{IsNumber}{\void}
679
680 Returns TRUE if the string is a number.
681
682 \membersection{wxString::IsSameAs}\label{wxstringissameas}
683
684 \constfunc{bool}{IsSameAs}{\param{const char*}{ psz}, \param{bool}{ caseSensitive = TRUE}}
685
686 Test for string equality, case-sensitive (default) or not.
687
688 caseSensitive is TRUE by default (case matters).
689
690 Returns TRUE if strings are equal, FALSE otherwise.
691
692 See also \helpref{Cmp}{wxstringcmp}, \helpref{CmpNoCase}{wxstringcmpnocase}, \helpref{IsSameAs}{wxstringissameas2}
693
694 \membersection{wxString::IsSameAs}\label{wxstringissameas2}
695
696 \constfunc{bool}{IsSameAs}{\param{char}{ c}, \param{bool}{ caseSensitive = TRUE}}
697
698 Test whether the string is equal to the single character {\it c}. The test is
699 case-sensitive if {\it caseSensitive} is TRUE (default) or not if it is FALSE.
700
701 Returns TRUE if the string is equal to the character, FALSE otherwise.
702
703 See also \helpref{Cmp}{wxstringcmp}, \helpref{CmpNoCase}{wxstringcmpnocase}, \helpref{IsSameAs}{wxstringissameas}
704
705 \membersection{wxString::IsWord}\label{wxstringisword}
706
707 \constfunc{bool}{IsWord}{\void}
708
709 Returns TRUE if the string is a word. TODO: what's the definition of a word?
710
711 \membersection{wxString::Last}\label{wxstringlast}
712
713 \constfunc{char}{Last}{\void}
714
715 Returns the last character.
716
717 \func{char\&}{Last}{\void}
718
719 Returns a reference to the last character (writable).
720
721 \membersection{wxString::Left}\label{wxstringleft}
722
723 \constfunc{wxString}{Left}{\param{size\_t}{ count}}
724
725 Returns the first {\it count} characters.
726
727 \constfunc{wxString}{Left}{\param{char}{ ch}}
728
729 Returns all characters before the first occurence of {\it ch}.
730 Returns the whole string if {\it ch} is not found.
731
732 \membersection{wxString::Len}\label{wxstringlen}
733
734 \constfunc{size\_t}{Len}{\void}
735
736 Returns the length of the string.
737
738 \membersection{wxString::Length}\label{wxstringlength}
739
740 \constfunc{size\_t}{Length}{\void}
741
742 Returns the length of the string (same as Len).
743
744 \membersection{wxString::Lower}\label{wxstringlower}
745
746 \constfunc{wxString}{Lower}{\void}
747
748 Returns this string converted to the lower case.
749
750 \membersection{wxString::LowerCase}\label{wxstringlowercase}
751
752 \func{void}{LowerCase}{\void}
753
754 Same as MakeLower.
755
756 \membersection{wxString::MakeLower}\label{wxstringmakelower}
757
758 \func{void}{MakeLower}{\void}
759
760 Converts all characters to lower case.
761
762 \membersection{wxString::MakeUpper}\label{wxstringmakeupper}
763
764 \func{void}{MakeUpper}{\void}
765
766 Converts all characters to upper case.
767
768 \membersection{wxString::Matches}\label{wxstringmatches}
769
770 \constfunc{bool}{Matches}{\param{const char*}{ szMask}}
771
772 Returns TRUE if the string contents matches a mask containing '*' and '?'.
773
774 \membersection{wxString::Mid}\label{wxstringmid}
775
776 \constfunc{wxString}{Mid}{\param{size\_t}{ first}, \param{size\_t}{ count = wxSTRING\_MAXLEN}}
777
778 Returns a substring starting at {\it first}, with length {\it count}, or the rest of
779 the string if {\it count} is the default value.
780
781 \membersection{wxString::Pad}\label{wxstringpad}
782
783 \func{wxString\&}{Pad}{\param{size\_t}{ count}, \param{char}{ pad = ' '}, \param{bool}{ fromRight = TRUE}}
784
785 Adds {\it count} copies of {\it pad} to the beginning, or to the end of the string (the default).
786
787 Removes spaces from the left or from the right (default).
788
789 \membersection{wxString::Prepend}\label{wxstringprepend}
790
791 \func{wxString\&}{Prepend}{\param{const wxString\&}{ str}}
792
793 Prepends {\it str} to this string, returning a reference to this string.
794
795 \membersection{wxString::Printf}\label{wxstringprintf}
796
797 \func{int}{Printf}{\param{const char* }{pszFormat}, \param{}{...}}
798
799 Similar to the standard function {\it sprintf()}. Returns the number of
800 characters written, or an integer less than zero on error.
801
802 {\bf NB:} This function will use a safe version of {\it vsprintf()} (usually called
803 {\it vsnprintf()}) whenever available to always allocate the buffer of correct
804 size. Unfortunately, this function is not available on all platforms and the
805 dangerous {\it vsprintf()} will be used then which may lead to buffer overflows.
806
807 \membersection{wxString::PrintfV}\label{wxstringprintfv}
808
809 \func{int}{PrintfV}{\param{const char* }{pszFormat}, \param{va\_list}{ argPtr}}
810
811 Similar to vprintf. Returns the number of characters written, or an integer less than zero
812 on error.
813
814 \membersection{wxString::Remove}\label{wxstringremove}
815
816 \func{wxString\&}{Remove}{\param{size\_t}{ pos}}
817
818 Same as Truncate. Removes the portion from {\it pos} to the end of the string.
819
820 \func{wxString\&}{Remove}{\param{size\_t}{ pos}, \param{size\_t}{ len}}
821
822 Removes the {\it len} characters from the string, starting at {\it pos}.
823
824 \membersection{wxString::RemoveLast}\label{wxstringremovelast}
825
826 \func{wxString\&}{RemoveLast}{\void}
827
828 Removes the last character.
829
830 \membersection{wxString::Replace}\label{wxstringreplace}
831
832 \func{size\_t}{Replace}{\param{const char*}{ szOld}, \param{const char*}{ szNew}, \param{bool}{ replaceAll = TRUE}}
833
834 Replace first (or all) occurences of substring with another one.
835
836 {\it replaceAll}: global replace (default), or only the first occurence.
837
838 Returns the number of replacements made.
839
840 \membersection{wxString::Right}\label{wxstringright}
841
842 \constfunc{wxString}{Right}{\param{size\_t}{ count}}
843
844 Returns the last {\it count} characters.
845
846 \membersection{wxString::SetChar}\label{wxstringsetchar}
847
848 \func{void}{SetChar}{\param{size\_t}{ n}, \param{char}{ch}}
849
850 Sets the character at position {\it n}.
851
852 \membersection{wxString::Shrink}\label{wxstringshrink}
853
854 \func{void}{Shrink}{\void}
855
856 Minimizes the string's memory. This can be useful after a call to
857 \helpref{Alloc()}{wxstringalloc} if too much memory were preallocated.
858
859 \membersection{wxString::sprintf}\label{wxstringsprintf}
860
861 \func{void}{sprintf}{\param{const char* }{ fmt}}
862
863 The same as Printf.
864
865 \membersection{wxString::Strip}\label{wxstringstrip}
866
867 \begin{verbatim}
868 enum stripType {leading = 0x1, trailing = 0x2, both = 0x3};
869 \end{verbatim}
870
871 \constfunc{wxString}{Strip}{\param{stripType}{ s = trailing}}
872
873 Strip characters at the front and/or end. The same as Trim except that it
874 doesn't change this string.
875
876 \membersection{wxString::SubString}\label{wxstringsubstring}
877
878 \constfunc{wxString}{SubString}{\param{size\_t}{ to}, \param{size\_t}{ from}}
879
880 Same as \helpref{Mid}{wxstringmid}.
881
882 \membersection{wxString::ToDouble}\label{wxstringtodouble}
883
884 \constfunc{bool}{To}{\param{double}{ *val}}
885
886 Attempts to convert the string to a floating point number. Returns TRUE on
887 suceess (the number is stored in the location pointed to by {\it val}) or FALSE
888 if the string does not represent such number.
889
890 \membersection{wxString::ToLong}\label{wxstringtolong}
891
892 \constfunc{bool}{To}{\param{long}{ *val}}
893
894 Attempts to convert the string to a signed integer. Returns TRUE on suceess
895 (the number is stored in the location pointed to by {\it val}) or FALSE if the
896 string does not represent such number.
897
898 \membersection{wxString::ToULong}\label{wxstringtoulong}
899
900 \constfunc{bool}{To}{\param{unsigned long}{ *val}}
901
902 Attempts to convert the string to an unsigned integer. Returns TRUE on suceess
903 (the number is stored in the location pointed to by {\it val}) or FALSE if the
904 string does not represent such number.
905
906 \membersection{wxString::Trim}\label{wxstringtrim}
907
908 \func{wxString\&}{Trim}{\param{bool}{ fromRight = TRUE}}
909
910 Removes spaces from the left or from the right (default).
911
912 \membersection{wxString::Truncate}\label{wxstringtruncate}
913
914 \func{wxString\&}{Truncate}{\param{size\_t}{ len}}
915
916 Truncate the string to the given length.
917
918 \membersection{wxString::UngetWriteBuf}\label{wxstringungetwritebuf}
919
920 \func{void}{UngetWriteBuf}{\void}
921
922 Puts the string back into a reasonable state, after
923 \rtfsp\helpref{wxString::GetWriteBuf}{wxstringgetwritebuf} was called.
924
925 \membersection{wxString::Upper}\label{wxstringupper}
926
927 \constfunc{wxString}{Upper}{\void}
928
929 Returns this string converted to upper case.
930
931 \membersection{wxString::UpperCase}\label{wxstringuppercase}
932
933 \func{void}{UpperCase}{\void}
934
935 The same as MakeUpper.
936
937 \membersection{wxString::operator!}\label{wxstringoperatornot}
938
939 \constfunc{bool}{operator!}{\void}
940
941 Empty string is FALSE, so !string will only return TRUE if the string is empty.
942 This allows the tests for NULLness of a {\it const char *} pointer and emptyness
943 of the string to look the same in the code and makes it easier to port old code
944 to wxString.
945
946 See also \helpref{IsEmpty()}{wxstringisempty}.
947
948 \membersection{wxString::operator $=$}\label{wxstringoperatorassign}
949
950 \func{wxString\&}{operator $=$}{\param{const wxString\&}{ str}}
951
952 \func{wxString\&}{operator $=$}{\param{const char*}{ psz}}
953
954 \func{wxString\&}{operator $=$}{\param{char}{ c}}
955
956 \func{wxString\&}{operator $=$}{\param{const unsigned char*}{ psz}}
957
958 \func{wxString\&}{operator $=$}{\param{const wchar\_t*}{ pwz}}
959
960 Assignment: the effect of each operation is the same as for the corresponding
961 constructor (see \helpref{wxString constructors}{wxstringconstruct}).
962
963 \membersection{operator wxString::$+$}\label{wxstringoperatorplus}
964
965 Concatenation: all these operators return a new strign equal to the sum of the
966 operands.
967
968 \func{wxString}{operator $+$}{\param{const wxString\&}{ x}, \param{const wxString\&}{ y}}
969
970 \func{wxString}{operator $+$}{\param{const wxString\&}{ x}, \param{const char*}{ y}}
971
972 \func{wxString}{operator $+$}{\param{const wxString\&}{ x}, \param{char}{ y}}
973
974 \func{wxString}{operator $+$}{\param{const char*}{ x}, \param{const wxString\&}{ y}}
975
976 \membersection{wxString::operator $+=$}\label{wxstringplusequal}
977
978 \func{void}{operator $+=$}{\param{const wxString\&}{ str}}
979
980 \func{void}{operator $+=$}{\param{const char*}{ psz}}
981
982 \func{void}{operator $+=$}{\param{char}{ c}}
983
984 Concatenation in place: the argument is appended to the string.
985
986 \membersection{wxString::operator []}\label{wxstringoperatorbracket}
987
988 \func{char\&}{operator []}{\param{size\_t}{ i}}
989
990 \func{char}{operator []}{\param{size\_t}{ i}}
991
992 \func{char}{operator []}{\param{int}{ i}}
993
994 Element extraction.
995
996 \membersection{wxString::operator ()}\label{wxstringoperatorparenth}
997
998 \func{wxString}{operator ()}{\param{size\_t}{ start}, \param{size\_t}{ len}}
999
1000 Same as Mid (substring extraction).
1001
1002 \membersection{wxString::operator \cinsert}\label{wxstringoperatorout}
1003
1004 \func{wxString\&}{operator \cinsert}{\param{const wxString\&}{ str}}
1005
1006 \func{wxString\&}{operator \cinsert}{\param{const char*}{ psz}}
1007
1008 \func{wxString\&}{operator \cinsert}{\param{char }{ch}}
1009
1010 Same as $+=$.
1011
1012 \func{wxString\&}{operator \cinsert}{\param{int}{ i}}
1013
1014 \func{wxString\&}{operator \cinsert}{\param{float}{ f}}
1015
1016 \func{wxString\&}{operator \cinsert}{\param{double}{ d}}
1017
1018 These functions work as C++ stream insertion operators: they insert the given
1019 value into the string. Precision or format cannot be set using them, you can use
1020 \helpref{Printf}{wxstringprintf} for this.
1021
1022 \membersection{wxString::operator \cextract}\label{wxstringoperatorin}
1023
1024 \func{friend istream\&}{operator \cextract}{\param{istream\&}{ is}, \param{wxString\&}{ str}}
1025
1026 Extraction from a stream.
1027
1028 \membersection{wxString::operator const char*}\label{wxstringoperatorconstcharpt}
1029
1030 \constfunc{}{operator const char*}{\void}
1031
1032 Implicit conversion to a C string.
1033
1034 \membersection{Comparison operators}\label{wxstringcomparison}
1035
1036 \func{bool}{operator $==$}{\param{const wxString\&}{ x}, \param{const wxString\&}{ y}}
1037
1038 \func{bool}{operator $==$}{\param{const wxString\&}{ x}, \param{const char*}{ t}}
1039
1040 \func{bool}{operator $!=$}{\param{const wxString\&}{ x}, \param{const wxString\&}{ y}}
1041
1042 \func{bool}{operator $!=$}{\param{const wxString\&}{ x}, \param{const char*}{ t}}
1043
1044 \func{bool}{operator $>$}{\param{const wxString\&}{ x}, \param{const wxString\&}{ y}}
1045
1046 \func{bool}{operator $>$}{\param{const wxString\&}{ x}, \param{const char*}{ t}}
1047
1048 \func{bool}{operator $>=$}{\param{const wxString\&}{ x}, \param{const wxString\&}{ y}}
1049
1050 \func{bool}{operator $>=$}{\param{const wxString\&}{ x}, \param{const char*}{ t}}
1051
1052 \func{bool}{operator $<$}{\param{const wxString\&}{ x}, \param{const wxString\&}{ y}}
1053
1054 \func{bool}{operator $<$}{\param{const wxString\&}{ x}, \param{const char*}{ t}}
1055
1056 \func{bool}{operator $<=$}{\param{const wxString\&}{ x}, \param{const wxString\&}{ y}}
1057
1058 \func{bool}{operator $<=$}{\param{const wxString\&}{ x}, \param{const char*}{ t}}
1059
1060 \wxheading{Remarks}
1061
1062 These comparisons are case-sensitive.
1063