]> git.saurik.com Git - wxWidgets.git/blame_incremental - docs/latex/wx/wxstring.tex
Misc small changes
[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 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{Cmp}{wxstringcmp}\\
103\helpref{CmpNoCase}{wxstringcmpnocase}\\
104\helpref{IsSameAs}{wxstringissameas}\\
105\helpref{Matches}{wxstringmatches}
106
107\membersection{Substring extraction}
108
109These functions allow to extract substring from this string. All of them don't
110modify the original string and return a new string containing the extracted
111substring.
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
124The MakeXXX() variants modify the string in place, while the other functions
125return a new string which containts the original text converted to the upper or
126lower 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
135These functions replace the standard {\it strchr()} and {\it strstr()}
136functions.
137
138\helpref{Find}{wxstringfind}\\
139\helpref{Replace}{wxstringreplace}
140
141\membersection{Conversion to numbers}
142
143The string provides functions for conversion to signed and unsigned integer and
144floating point numbers. All three functions take a pointer to the variable to
145put the numeric value in and return TRUE if the {\bf entire} string could be
146converted 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
154Both formatted versions (\helpref{Printf}{wxstringprintf}) and stream-like
155insertion operators exist (for basic types only). Additionally, the
156\helpref{Format}{wxstringformat} function allows to use simply append
157formatted 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
177These are "advanced" functions and they will be needed quite rarily.
178\helpref{Alloc}{wxstringalloc} and \helpref{Shrink}{wxstringshrink} are only
179interesting for optimization purposes.
180\helpref{GetWriteBuf}{wxstringgetwritebuf} may be very useful when working with
181some external API which requires the caller to provide a writable buffer, but
182extreme care should be taken when using it: before performing any other
183operation on the string \helpref{UngetWriteBuf}{wxstringungetwritebuf} {\bf
184must} be called!
185
186\helpref{Alloc}{wxstringalloc}\\
187\helpref{Shrink}{wxstringshrink}\\
188\helpref{GetWriteBuf}{wxstringgetwritebuf}\\
189\helpref{UngetWriteBuf}{wxstringungetwritebuf}
190
191\membersection{Miscellaneous}
192
193Other string functions.
194
195\helpref{Trim}{wxstringtrim}\\
196\helpref{Pad}{wxstringpad}\\
197\helpref{Truncate}{wxstringtruncate}
198
199\membersection{wxWindows 1.xx compatiblity functions}
200
201These functiosn are deprecated, please consider using new wxWindows 2.0
202functions 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
224The supported functions are only listed here, please see any STL reference for
225their 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
385Default constructor.
386
387\func{}{wxString}{\param{const wxString\&}{ x}}
388
389Copy constructor.
390
391\func{}{wxString}{\param{char}{ ch}, \param{size\_t}{ n = 1}}
392
393Constructs 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
397Takes first {\it nLength} characters from the C string {\it psz}.
398The 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
402For compilers using unsigned char: takes first {\it nLength} characters from the C string {\it psz}.
403The default value of wxSTRING\_MAXLEN means take all the string.
404
405\func{}{wxString}{\param{const wchar\_t*}{ psz}}
406
407Constructs a string from the wide (UNICODE) string.
408
409\membersection{wxString::\destruct{wxString}}\label{wxstringdestruct}
410
411\func{}{\destruct{wxString}}{\void}
412
413String 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
419Preallocate enough space for wxString to store {\it nLen} characters. This function
420may be used to increase speed when the string is constructed by repeated
421concatenation as in
422
423\begin{verbatim}
424
425// delete all vowels from the string
426wxString 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
445because it will avoid the need of reallocating string memory many times (in case
446of long strings). Note that it does not set the maximal length of a string - it
447will still expand if more than {\it nLen} characters are stored in it. Also, it
448does not truncate the existing string (use
449\helpref{Truncate()}{wxstringtruncate} for this) even if its current length is
450greater than {\it nLen}
451
452\membersection{wxString::Append}\label{wxstringappend}
453
454\func{wxString\&}{Append}{\param{const char*}{ psz}}
455
456Concatenates {\it psz} to this string, returning a reference to it.
457
458\func{wxString\&}{Append}{\param{char}{ ch}, \param{int}{ count = 1}}
459
460Concatenates character {\it ch} to this string, {\it count} times, returning a reference
461to it.
462
463\membersection{wxString::AfterFirst}\label{wxstringafterfirst}
464
465\constfunc{wxString}{AfterFirst}{\param{char}{ ch}}
466
467Gets all the characters after the first occurence of {\it ch}.
468Returns 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
474Gets all the characters after the last occurence of {\it ch}.
475Returns 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
481Gets all characters before the first occurence of {\it ch}.
482Returns 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
488Gets all characters before the last occurence of {\it ch}.
489Returns 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
495Returns a pointer to the string data.
496
497\membersection{wxString::Clear}\label{wxstringclear}
498
499\func{void}{Clear}{\void}
500
501Empties the string and frees memory occupied by it.
502
503See also: \helpref{Empty}{wxstringempty}
504
505\membersection{wxString::Cmp}\label{wxstringcmp}
506
507\constfunc{int}{Cmp}{\param{const char*}{ psz}}
508
509Case-sensitive comparison.
510
511Returns a positive value if the string is greater than the argument, zero if
512it si equal to it or negative value if it is less than argument (same semantics
513as the standard {\it strcmp()} function).
514
515See also \helpref{CmpNoCase}{wxstringcmpnocase}, \helpref{IsSameAs}{wxstringissameas}.
516
517\membersection{wxString::CmpNoCase}\label{wxstringcmpnocase}
518
519\constfunc{int}{CmpNoCase}{\param{const char*}{ psz}}
520
521Case-insensitive comparison.
522
523Returns a positive value if the string is greater than the argument, zero if
524it si equal to it or negative value if it is less than argument (same semantics
525as the standard {\it strcmp()} function).
526
527See 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
533enum caseCompare {exact, ignoreCase};
534\end{verbatim}
535
536\constfunc{int}{CompareTo}{\param{const char*}{ psz}, \param{caseCompare}{ cmp = exact}}
537
538Case-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
544Returns 1 if target appears anyhere in wxString; else 0.
545
546\membersection{wxString::Empty}\label{wxstringempty}
547
548\func{void}{Empty}{\void}
549
550Makes the string empty, but doesn't free memory occupied by the string.
551
552See also: \helpref{Clear()}{wxstringclear}.
553
554\membersection{wxString::Find}\label{wxstringfind}
555
556\constfunc{int}{Find}{\param{char}{ ch}, \param{bool}{ fromEnd = FALSE}}
557
558Searches for the given character. Returns the starting index, or -1 if not found.
559
560\constfunc{int}{Find}{\param{const char*}{ sz}}
561
562Searches 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
574Returns 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
580This 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
591This 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
602Returns 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
608Returns the character at position {\it n} (read-only).
609
610\membersection{wxString::GetData}\label{wxstringgetdata}
611
612\constfunc{const char*}{GetData}{\void}
613
614wxWindows 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
620Returns 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
626Returns a writable buffer of at least {\it len} bytes.
627
628Call \helpref{wxString::UngetWriteBuf}{wxstringungetwritebuf} as soon as possible
629to 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
635Same as \helpref{wxString::Find}{wxstringfind}.
636
637\constfunc{size\_t}{Index}{\param{const char*}{ sz}}
638
639Same as \helpref{wxString::Find}{wxstringfind}.
640
641\constfunc{size\_t}{Index}{\param{const char*}{ sz}, \param{bool}{ caseSensitive = TRUE}, \param{bool}{ fromEnd = FALSE}}
642
643Search the element in the array, starting from either side.
644
645If {\it fromEnd} is TRUE, reverse search direction.
646
647If {\bf caseSensitive}, comparison is case sensitive (the default).
648
649Returns 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
662Returns TRUE if the string is ASCII.
663
664\membersection{wxString::IsEmpty}\label{wxstringisempty}
665
666\constfunc{bool}{IsEmpty}{\void}
667
668Returns TRUE if the string is NULL.
669
670\membersection{wxString::IsNull}\label{wxstringisnull}
671
672\constfunc{bool}{IsNull}{\void}
673
674Returns TRUE if the string is NULL (same as IsEmpty).
675
676\membersection{wxString::IsNumber}\label{wxstringisnumber}
677
678\constfunc{bool}{IsNumber}{\void}
679
680Returns 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
686Test for string equality, case-sensitive (default) or not.
687
688caseSensitive is TRUE by default (case matters).
689
690Returns TRUE if strings are equal, FALSE otherwise.
691
692See 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
698Test whether the string is equal to the single character {\it c}. The test is
699case-sensitive if {\it caseSensitive} is TRUE (default) or not if it is FALSE.
700
701Returns TRUE if the string is equal to the character, FALSE otherwise.
702
703See also \helpref{Cmp}{wxstringcmp}, \helpref{CmpNoCase}{wxstringcmpnocase}, \helpref{IsSameAs}{wxstringissameas}
704
705\membersection{wxString::IsWord}\label{wxstringisword}
706
707\constfunc{bool}{IsWord}{\void}
708
709Returns 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
715Returns the last character.
716
717\func{char\&}{Last}{\void}
718
719Returns a reference to the last character (writable).
720
721\membersection{wxString::Left}\label{wxstringleft}
722
723\constfunc{wxString}{Left}{\param{size\_t}{ count}}
724
725Returns the first {\it count} characters.
726
727\constfunc{wxString}{Left}{\param{char}{ ch}}
728
729Returns all characters before the first occurence of {\it ch}.
730Returns the whole string if {\it ch} is not found.
731
732\membersection{wxString::Len}\label{wxstringlen}
733
734\constfunc{size\_t}{Len}{\void}
735
736Returns the length of the string.
737
738\membersection{wxString::Length}\label{wxstringlength}
739
740\constfunc{size\_t}{Length}{\void}
741
742Returns the length of the string (same as Len).
743
744\membersection{wxString::Lower}\label{wxstringlower}
745
746\constfunc{wxString}{Lower}{\void}
747
748Returns this string converted to the lower case.
749
750\membersection{wxString::LowerCase}\label{wxstringlowercase}
751
752\func{void}{LowerCase}{\void}
753
754Same as MakeLower.
755
756\membersection{wxString::MakeLower}\label{wxstringmakelower}
757
758\func{void}{MakeLower}{\void}
759
760Converts all characters to lower case.
761
762\membersection{wxString::MakeUpper}\label{wxstringmakeupper}
763
764\func{void}{MakeUpper}{\void}
765
766Converts all characters to upper case.
767
768\membersection{wxString::Matches}\label{wxstringmatches}
769
770\constfunc{bool}{Matches}{\param{const char*}{ szMask}}
771
772Returns 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
778Returns a substring starting at {\it first}, with length {\it count}, or the rest of
779the 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
785Adds {\it count} copies of {\it pad} to the beginning, or to the end of the string (the default).
786
787Removes 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
793Prepends {\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
799Similar to the standard function {\it sprintf()}. Returns the number of
800characters 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
804size. Unfortunately, this function is not available on all platforms and the
805dangerous {\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
811Similar to vprintf. Returns the number of characters written, or an integer less than zero
812on error.
813
814\membersection{wxString::Remove}\label{wxstringremove}
815
816\func{wxString\&}{Remove}{\param{size\_t}{ pos}}
817
818Same 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
822Removes 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
828Removes 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
834Replace first (or all) occurences of substring with another one.
835
836{\it replaceAll}: global replace (default), or only the first occurence.
837
838Returns the number of replacements made.
839
840\membersection{wxString::Right}\label{wxstringright}
841
842\constfunc{wxString}{Right}{\param{size\_t}{ count}}
843
844Returns 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
850Sets the character at position {\it n}.
851
852\membersection{wxString::Shrink}\label{wxstringshrink}
853
854\func{void}{Shrink}{\void}
855
856Minimizes 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
863The same as Printf.
864
865\membersection{wxString::Strip}\label{wxstringstrip}
866
867\begin{verbatim}
868enum stripType {leading = 0x1, trailing = 0x2, both = 0x3};
869\end{verbatim}
870
871\constfunc{wxString}{Strip}{\param{stripType}{ s = trailing}}
872
873Strip characters at the front and/or end. The same as Trim except that it
874doesn'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
880Same as \helpref{Mid}{wxstringmid}.
881
882\membersection{wxString::ToDouble}\label{wxstringtodouble}
883
884\constfunc{bool}{To}{\param{double}{ *val}}
885
886Attempts to convert the string to a floating point number. Returns TRUE on
887suceess (the number is stored in the location pointed to by {\it val}) or FALSE
888if the string does not represent such number.
889
890\membersection{wxString::ToLong}\label{wxstringtolong}
891
892\constfunc{bool}{To}{\param{long}{ *val}}
893
894Attempts 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
896string does not represent such number.
897
898\membersection{wxString::ToULong}\label{wxstringtoulong}
899
900\constfunc{bool}{To}{\param{unsigned long}{ *val}}
901
902Attempts 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
904string does not represent such number.
905
906\membersection{wxString::Trim}\label{wxstringtrim}
907
908\func{wxString\&}{Trim}{\param{bool}{ fromRight = TRUE}}
909
910Removes 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
916Truncate the string to the given length.
917
918\membersection{wxString::UngetWriteBuf}\label{wxstringungetwritebuf}
919
920\func{void}{UngetWriteBuf}{\void}
921
922Puts 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
929Returns this string converted to upper case.
930
931\membersection{wxString::UpperCase}\label{wxstringuppercase}
932
933\func{void}{UpperCase}{\void}
934
935The same as MakeUpper.
936
937\membersection{wxString::operator!}\label{wxstringoperatornot}
938
939\constfunc{bool}{operator!}{\void}
940
941Empty string is FALSE, so !string will only return TRUE if the string is empty.
942This allows the tests for NULLness of a {\it const char *} pointer and emptyness
943of the string to look the same in the code and makes it easier to port old code
944to wxString.
945
946See 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
960Assignment: the effect of each operation is the same as for the corresponding
961constructor (see \helpref{wxString constructors}{wxstringconstruct}).
962
963\membersection{operator wxString::$+$}\label{wxstringoperatorplus}
964
965Concatenation: all these operators return a new strign equal to the sum of the
966operands.
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
984Concatenation 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
994Element extraction.
995
996\membersection{wxString::operator ()}\label{wxstringoperatorparenth}
997
998\func{wxString}{operator ()}{\param{size\_t}{ start}, \param{size\_t}{ len}}
999
1000Same 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
1010Same 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
1018These functions work as C++ stream insertion operators: they insert the given
1019value 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
1026Extraction from a stream.
1027
1028\membersection{wxString::operator const char*}\label{wxstringoperatorconstcharpt}
1029
1030\constfunc{}{operator const char*}{\void}
1031
1032Implicit 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
1062These comparisons are case-sensitive.
1063