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