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