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