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