]> git.saurik.com Git - wxWidgets.git/blame_incremental - docs/latex/wx/wxstring.tex
Moved desktop margin options to a more sensible place
[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.
5
6As explained there, wxString implements most of the methods of the std::string
7class.
8These standard functions are not documented in this manual, please see the
9\urlref{STL documentation}{http://www.cppreference.com/cppstl.html}).
10The behaviour of all these functions is identical to the behaviour described
11there.
12
13You may notice that wxString sometimes has many functions which do the same
14thing like, for example, \helpref{Length()}{wxstringlength},
15\helpref{Len()}{wxstringlen} and {\tt length()} which all return the string
16length. In all cases of such duplication the {\tt std::string}-compatible
17method ({\tt length()} in this case, always the lowercase version) should be
18used as it will ensure smoother transition to {\tt std::string} when wxWidgets
19starts using it instead of wxString.
20
21\wxheading{Derived from}
22
23None
24
25\wxheading{Include files}
26
27<wx/string.h>
28
29\wxheading{Library}
30
31\helpref{wxBase}{librarieslist}
32
33\wxheading{Predefined objects}
34
35Objects:
36
37{\bf wxEmptyString}
38
39\wxheading{See also}
40
41\helpref{wxString overview}{wxstringoverview}, \helpref{Unicode overview}{unicode}
42
43\latexignore{\rtfignore{\wxheading{Function groups}}}
44
45
46\membersection{Constructors and assignment operators}\label{constructorsinwxstring}
47
48A string may be constructed either from a C string, (some number of copies of)
49a single character or a wide (UNICODE) string. For all constructors (except the
50default which creates an empty string) there is also a corresponding assignment
51operator.
52
53\helpref{wxString}{wxstringconstruct}\\
54\helpref{operator $=$}{wxstringoperatorassign}\\
55\helpref{\destruct{wxString}}{wxstringdestruct}
56
57
58\membersection{String length}\label{lengthfunctionsinwxstring}
59
60These functions return the string length and check whether the string is empty
61or empty it.
62
63\helpref{Len}{wxstringlen}\\
64\helpref{IsEmpty}{wxstringisempty}\\
65\helpref{operator!}{wxstringoperatornot}\\
66\helpref{Empty}{wxstringempty}\\
67\helpref{Clear}{wxstringclear}
68
69
70\membersection{Character access}\label{characteraccessinwxstring}
71
72Many functions in this section take a character index in the string. As with C
73strings and/or arrays, the indices start from $0$, so the first character of a
74string is string[$0$]. Attempt to access a character beyond the end of the
75string (which may be even $0$ if the string is empty) will provoke an assert
76failure in \helpref{debug build}{debuggingoverview}, but no checks are done in
77release builds.
78
79This section also contains both implicit and explicit conversions to C style
80strings. Although implicit conversion is quite convenient, it is advised to use
81explicit \helpref{c\_str()}{wxstringcstr} method for the sake of clarity. Also
82see \helpref{overview}{wxstringadvices} for the cases where it is necessary to
83use it.
84
85\helpref{GetChar}{wxstringgetchar}\\
86\helpref{GetWritableChar}{wxstringgetwritablechar}\\
87\helpref{SetChar}{wxstringsetchar}\\
88\helpref{Last}{wxstringlast}\\
89\helpref{operator []}{wxstringoperatorbracket}\\
90\helpref{c\_str}{wxstringcstr}\\
91\helpref{mb\_str}{wxstringmbstr}\\
92\helpref{wc\_str}{wxstringwcstr}\\
93\helpref{fn\_str}{wxstringfnstr}\\
94\helpref{operator const char*}{wxstringoperatorconstcharpt}
95
96
97\membersection{Concatenation}\label{concatenationinwxstring}
98
99Anything may be concatenated (appended to) with a string. However, you can't
100append something to a C string (including literal constants), so to do this it
101should be converted to a wxString first.
102
103\helpref{operator \cinsert}{wxstringoperatorout}\\
104\helpref{operator $+=$}{wxstringplusequal}\\
105\helpref{operator $+$}{wxstringoperatorplus}\\
106\helpref{Append}{wxstringappend}\\
107\helpref{Prepend}{wxstringprepend}
108
109
110\membersection{Comparison}\label{comparisoninwxstring}
111
112The default comparison function \helpref{Cmp}{wxstringcmp} is case-sensitive and
113so is the default version of \helpref{IsSameAs}{wxstringissameas}. For case
114insensitive comparisons you should use \helpref{CmpNoCase}{wxstringcmpnocase} or
115give a second parameter to IsSameAs. This last function is may be more
116convenient if only equality of the strings matters because it returns a boolean
117\true value if the strings are the same and not 0 (which is usually false in C)
118as {\tt Cmp()} does.
119
120\helpref{Matches}{wxstringmatches} is a poor man's regular expression matcher:
121it only understands '*' and '?' metacharacters in the sense of DOS command line
122interpreter.
123
124\helpref{StartsWith}{wxstringstartswith} is helpful when parsing a line of
125text which should start with some predefined prefix and is more efficient than
126doing direct string comparison as you would also have to precalculate the
127length of the prefix then.
128
129\helpref{Cmp}{wxstringcmp}\\
130\helpref{CmpNoCase}{wxstringcmpnocase}\\
131\helpref{IsSameAs}{wxstringissameas}\\
132\helpref{Matches}{wxstringmatches}\\
133\helpref{StartsWith}{wxstringstartswith}\\
134\helpref{EndsWith}{wxstringendswith}
135
136
137\membersection{Substring extraction}\label{substringextractioninwxstring}
138
139These functions allow to extract substring from this string. All of them don't
140modify the original string and return a new string containing the extracted
141substring.
142
143\helpref{Mid}{wxstringmid}\\
144\helpref{operator()}{wxstringoperatorparenth}\\
145\helpref{Left}{wxstringleft}\\
146\helpref{Right}{wxstringright}\\
147\helpref{BeforeFirst}{wxstringbeforefirst}\\
148\helpref{BeforeLast}{wxstringbeforelast}\\
149\helpref{AfterFirst}{wxstringafterfirst}\\
150\helpref{AfterLast}{wxstringafterlast}\\
151\helpref{StartsWith}{wxstringstartswith}\\
152\helpref{EndsWith}{wxstringendswith}
153
154
155
156\membersection{Case conversion}\label{caseconversioninwxstring}
157
158The MakeXXX() variants modify the string in place, while the other functions
159return a new string which contains the original text converted to the upper or
160lower case and leave the original string unchanged.
161
162\helpref{MakeUpper}{wxstringmakeupper}\\
163\helpref{Upper}{wxstringupper}\\
164\helpref{MakeLower}{wxstringmakelower}\\
165\helpref{Lower}{wxstringlower}
166
167
168\membersection{Searching and replacing}\label{searchingandreplacinginwxstring}
169
170These functions replace the standard {\it strchr()} and {\it strstr()}
171functions.
172
173\helpref{Find}{wxstringfind}\\
174\helpref{Replace}{wxstringreplace}
175
176
177\membersection{Conversion to numbers}\label{conversiontonumbersinwxstring}
178
179The string provides functions for conversion to signed and unsigned integer and
180floating point numbers. All three functions take a pointer to the variable to
181put the numeric value in and return \true if the {\bf entire} string could be
182converted to a number.
183
184\helpref{ToLong}{wxstringtolong}\\
185\helpref{ToLongLong}{wxstringtolonglong}\\
186\helpref{ToULong}{wxstringtoulong}\\
187\helpref{ToULongLong}{wxstringtoulonglong}\\
188\helpref{ToDouble}{wxstringtodouble}
189
190
191\membersection{Writing values into the string}\label{writingintostringinwxstring}
192
193Both formatted versions (\helpref{Printf}{wxstringprintf}) and stream-like
194insertion operators exist (for basic types only). Additionally, the
195\helpref{Format}{wxstringformat} function allows to use simply append
196formatted value to a string:
197
198\begin{verbatim}
199 // the following 2 snippets are equivalent
200
201 wxString s = "...";
202 s += wxString::Format("%d", n);
203
204 wxString s;
205 s.Printf("...%d", n);
206\end{verbatim}
207
208\helpref{Format}{wxstringformat}\\
209\helpref{FormatV}{wxstringformatv}\\
210\helpref{Printf}{wxstringprintf}\\
211\helpref{PrintfV}{wxstringprintfv}\\
212\helpref{operator \cinsert}{wxstringoperatorout}
213
214
215\membersection{Memory management}\label{memoryinwxstring}
216
217These are "advanced" functions and they will be needed quite rarely.
218\helpref{Alloc}{wxstringalloc} and \helpref{Shrink}{wxstringshrink} are only
219interesting for optimization purposes.
220\helpref{wxStringBuffer}{wxstringbuffer}
221and \helpref{wxStringBufferLength}{wxstringbufferlength} classes may be very
222useful when working with some external API which requires the caller to provide
223a writable buffer.
224
225\helpref{Alloc}{wxstringalloc}\\
226\helpref{Shrink}{wxstringshrink}\\
227\helpref{wxStringBuffer}{wxstringbuffer}\\
228\helpref{wxStringBufferLength}{wxstringbufferlength}
229
230
231\membersection{Miscellaneous}\label{miscellaneousinwxstring}
232
233Other string functions.
234
235\helpref{Trim}{wxstringtrim}\\
236\helpref{Truncate}{wxstringtruncate}\\
237\helpref{Pad}{wxstringpad}
238
239
240\membersection{wxWidgets 1.xx compatibility functions}\label{backwardcompatibilityinwxstring}
241
242These functions are deprecated, please consider using new wxWidgets 2.0
243functions instead of them (or, even better, std::string compatible variants).
244
245% keep ordered alphabetically
246\helpref{CompareTo}{wxstringcompareto}\\
247\helpref{Contains}{wxstringcontains}\\
248\helpref{First}{wxstringfirst}\\
249\helpref{Freq}{wxstringfreq}\\
250\helpref{Index}{wxstringindex}\\
251\helpref{IsAscii}{wxstringisascii}\\
252\helpref{IsNull}{wxstringisnull}\\
253\helpref{IsNumber}{wxstringisnumber}\\
254\helpref{IsWord}{wxstringisword}\\
255\helpref{Last}{wxstringlast}\\
256\helpref{Length}{wxstringlength}\\
257\helpref{LowerCase}{wxstringlowercase}\\
258\helpref{Remove}{wxstringremove}\\
259\helpref{Strip}{wxstringstrip}\\
260\helpref{SubString}{wxstringsubstring}\\
261\helpref{UpperCase}{wxstringuppercase}
262
263
264\membersection{std::string compatibility functions}\label{wxstringat}
265
266The supported functions are only listed here, please see any STL reference for
267their documentation.
268
269\begin{verbatim}
270 // take nLen chars starting at nPos
271 wxString(const wxString& str, size_t nPos, size_t nLen);
272 // take all characters from pStart to pEnd (poor man's iterators)
273 wxString(const void *pStart, const void *pEnd);
274
275 // lib.string.capacity
276 // return the length of the string
277 size_t size() const;
278 // return the length of the string
279 size_t length() const;
280 // return the maximum size of the string
281 size_t max_size() const;
282 // resize the string, filling the space with c if c != 0
283 void resize(size_t nSize, char ch = '\0');
284 // delete the contents of the string
285 void clear();
286 // returns true if the string is empty
287 bool empty() const;
288
289 // lib.string.access
290 // return the character at position n
291 char at(size_t n) const;
292 // returns the writable character at position n
293 char& at(size_t n);
294
295 // lib.string.modifiers
296 // append a string
297 wxString& append(const wxString& str);
298 // append elements str[pos], ..., str[pos+n]
299 wxString& append(const wxString& str, size_t pos, size_t n);
300 // append first n (or all if n == npos) characters of sz
301 wxString& append(const char *sz, size_t n = npos);
302
303 // append n copies of ch
304 wxString& append(size_t n, char ch);
305
306 // same as `this_string = str'
307 wxString& assign(const wxString& str);
308 // same as ` = str[pos..pos + n]
309 wxString& assign(const wxString& str, size_t pos, size_t n);
310 // same as `= first n (or all if n == npos) characters of sz'
311 wxString& assign(const char *sz, size_t n = npos);
312 // same as `= n copies of ch'
313 wxString& assign(size_t n, char ch);
314
315 // insert another string
316 wxString& insert(size_t nPos, const wxString& str);
317 // insert n chars of str starting at nStart (in str)
318 wxString& insert(size_t nPos, const wxString& str, size_t nStart, size_t n);
319
320 // insert first n (or all if n == npos) characters of sz
321 wxString& insert(size_t nPos, const char *sz, size_t n = npos);
322 // insert n copies of ch
323 wxString& insert(size_t nPos, size_t n, char ch);
324
325 // delete characters from nStart to nStart + nLen
326 wxString& erase(size_t nStart = 0, size_t nLen = npos);
327
328 // replaces the substring of length nLen starting at nStart
329 wxString& replace(size_t nStart, size_t nLen, const char* sz);
330 // replaces the substring with nCount copies of ch
331 wxString& replace(size_t nStart, size_t nLen, size_t nCount, char ch);
332 // replaces a substring with another substring
333 wxString& replace(size_t nStart, size_t nLen,
334 const wxString& str, size_t nStart2, size_t nLen2);
335 // replaces the substring with first nCount chars of sz
336 wxString& replace(size_t nStart, size_t nLen,
337 const char* sz, size_t nCount);
338
339 // swap two strings
340 void swap(wxString& str);
341
342 // All find() functions take the nStart argument which specifies the
343 // position to start the search on, the default value is 0. All functions
344 // return npos if there were no match.
345
346 // find a substring
347 size_t find(const wxString& str, size_t nStart = 0) const;
348
349 // find first n characters of sz
350 size_t find(const char* sz, size_t nStart = 0, size_t n = npos) const;
351
352 // find the first occurrence of character ch after nStart
353 size_t find(char ch, size_t nStart = 0) const;
354
355 // rfind() family is exactly like find() but works right to left
356
357 // as find, but from the end
358 size_t rfind(const wxString& str, size_t nStart = npos) const;
359
360 // as find, but from the end
361 size_t rfind(const char* sz, size_t nStart = npos,
362 size_t n = npos) const;
363 // as find, but from the end
364 size_t rfind(char ch, size_t nStart = npos) const;
365
366 // find first/last occurrence of any character in the set
367
368 //
369 size_t find_first_of(const wxString& str, size_t nStart = 0) const;
370 //
371 size_t find_first_of(const char* sz, size_t nStart = 0) const;
372 // same as find(char, size_t)
373 size_t find_first_of(char c, size_t nStart = 0) const;
374 //
375 size_t find_last_of (const wxString& str, size_t nStart = npos) const;
376 //
377 size_t find_last_of (const char* s, size_t nStart = npos) const;
378 // same as rfind(char, size_t)
379 size_t find_last_of (char c, size_t nStart = npos) const;
380
381 // find first/last occurrence of any character not in the set
382
383 //
384 size_t find_first_not_of(const wxString& str, size_t nStart = 0) const;
385 //
386 size_t find_first_not_of(const char* s, size_t nStart = 0) const;
387 //
388 size_t find_first_not_of(char ch, size_t nStart = 0) const;
389 //
390 size_t find_last_not_of(const wxString& str, size_t nStart=npos) const;
391 //
392 size_t find_last_not_of(const char* s, size_t nStart = npos) const;
393 //
394 size_t find_last_not_of(char ch, size_t nStart = npos) const;
395
396 // All compare functions return a negative, zero or positive value
397 // if the [sub]string is less, equal or greater than the compare() argument.
398
399 // just like strcmp()
400 int compare(const wxString& str) const;
401 // comparison with a substring
402 int compare(size_t nStart, size_t nLen, const wxString& str) const;
403 // comparison of 2 substrings
404 int compare(size_t nStart, size_t nLen,
405 const wxString& str, size_t nStart2, size_t nLen2) const;
406 // just like strcmp()
407 int compare(const char* sz) const;
408 // substring comparison with first nCount characters of sz
409 int compare(size_t nStart, size_t nLen,
410 const char* sz, size_t nCount = npos) const;
411
412 // substring extraction
413 wxString substr(size_t nStart = 0, size_t nLen = npos) const;
414\end{verbatim}
415
416%%%%% MEMBERS HERE %%%%%
417\helponly{\insertatlevel{2}{
418
419\wxheading{Members}
420
421}}
422
423
424\membersection{wxString::wxString}\label{wxstringconstruct}
425
426\func{}{wxString}{\void}
427
428Default constructor. Initializes the string to {\tt ""} (empty string).
429
430\func{}{wxString}{\param{const wxString\&}{ x}}
431
432Copy constructor.
433
434\func{}{wxString}{\param{wxChar}{ ch}, \param{size\_t}{ n = 1}}
435
436Constructs a string of {\it n} copies of character {\it ch}.
437
438\func{}{wxString}{\param{const wxChar*}{ psz}, \param{size\_t}{ nLength = wxSTRING\_MAXLEN}}
439
440Takes first {\it nLength} characters from the C string {\it psz}.
441The default value of {\tt wxSTRING\_MAXLEN} means to take all the string.
442
443Note that this constructor may be used even if {\it psz} points to a buffer
444with binary data (i.e. containing {\tt NUL} characters) as long as you provide
445the correct value for {\it nLength}. However, the default form of it works
446only with strings without intermediate {\tt NUL}s because it uses
447{\tt strlen()} to calculate the effective length and it would not give correct
448results otherwise.
449
450\func{}{wxString}{\param{const unsigned char*}{ psz}, \param{size\_t}{ nLength = wxSTRING\_MAXLEN}}
451
452For compilers using unsigned char: takes first {\it nLength} characters from the C string {\it psz}.
453The default value of {\tt wxSTRING\_MAXLEN} means take all the string.
454For ANSI builds only (note the use of {\tt char} instead of {\tt wxChar}).
455
456\wxheading{Constructors with conversion}
457
458The following constructors allow you to construct wxString from a wide string
459in ANSI build or from a C string in Unicode build.
460
461\func{}{wxString}{\param{const wchar\_t*}{ psz}, \param{const wxMBConv\&}{ conv}, \param{size\_t}{ nLength = wxSTRING\_MAXLEN}}
462
463Initializes the string from first \arg{nLength} characters of wide string.
464The default value of {\tt wxSTRING\_MAXLEN} means take all the string.
465In ANSI build, \arg{conv}'s
466\helpref{WC2MB}{wxmbconvwc2mb} method is called to
467convert \arg{psz} to wide string. It is ignored in Unicode build.
468
469\func{}{wxString}{\param{const char*}{ psz}, \param{const wxMBConv\&}{ conv = wxConvLibc}, \param{size\_t}{ nLength = wxSTRING\_MAXLEN}}
470
471Initializes the string from first \arg{nLength} characters of C string.
472The default value of {\tt wxSTRING\_MAXLEN} means take all the string.
473In Unicode build, \arg{conv}'s
474\helpref{MB2WC}{wxmbconvmb2wc} method is called to
475convert \arg{psz} to wide string (the default converter uses current locale's
476charset). It is ignored in ANSI build.
477
478\wxheading{See also}
479
480\helpref{wxMBConv classes}{mbconvclasses}, \helpref{mb\_str}{wxstringmbstr},
481\helpref{wc\_str}{wxstringwcstr}
482
483
484\membersection{wxString::\destruct{wxString}}\label{wxstringdestruct}
485
486\func{}{\destruct{wxString}}{\void}
487
488String destructor. Note that this is not virtual, so wxString must not be inherited from.
489
490
491\membersection{wxString::Alloc}\label{wxstringalloc}
492
493\func{void}{Alloc}{\param{size\_t}{ nLen}}
494
495Preallocate enough space for wxString to store {\it nLen} characters. This function
496may be used to increase speed when the string is constructed by repeated
497concatenation as in
498
499\begin{verbatim}
500
501// delete all vowels from the string
502wxString DeleteAllVowels(const wxString& original)
503{
504 wxString result;
505
506 size_t len = original.length();
507
508 result.Alloc(len);
509
510 for ( size_t n = 0; n < len; n++ )
511 {
512 if ( strchr("aeuio", tolower(original[n])) == NULL )
513 result += original[n];
514 }
515
516 return result;
517}
518
519\end{verbatim}
520
521because it will avoid the need to reallocate string memory many times (in case
522of long strings). Note that it does not set the maximal length of a string - it
523will still expand if more than {\it nLen} characters are stored in it. Also, it
524does not truncate the existing string (use
525\helpref{Truncate()}{wxstringtruncate} for this) even if its current length is
526greater than {\it nLen}
527
528
529\membersection{wxString::Append}\label{wxstringappend}
530
531\func{wxString\&}{Append}{\param{const wxChar*}{ psz}}
532
533Concatenates {\it psz} to this string, returning a reference to it.
534
535\func{wxString\&}{Append}{\param{wxChar}{ ch}, \param{int}{ count = 1}}
536
537Concatenates character {\it ch} to this string, {\it count} times, returning a reference
538to it.
539
540
541\membersection{wxString::AfterFirst}\label{wxstringafterfirst}
542
543\constfunc{wxString}{AfterFirst}{\param{wxChar}{ ch}}
544
545Gets all the characters after the first occurrence of {\it ch}.
546Returns the empty string if {\it ch} is not found.
547
548
549\membersection{wxString::AfterLast}\label{wxstringafterlast}
550
551\constfunc{wxString}{AfterLast}{\param{wxChar}{ ch}}
552
553Gets all the characters after the last occurrence of {\it ch}.
554Returns the whole string if {\it ch} is not found.
555
556
557\membersection{wxString::BeforeFirst}\label{wxstringbeforefirst}
558
559\constfunc{wxString}{BeforeFirst}{\param{wxChar}{ ch}}
560
561Gets all characters before the first occurrence of {\it ch}.
562Returns the whole string if {\it ch} is not found.
563
564
565\membersection{wxString::BeforeLast}\label{wxstringbeforelast}
566
567\constfunc{wxString}{BeforeLast}{\param{wxChar}{ ch}}
568
569Gets all characters before the last occurrence of {\it ch}.
570Returns the empty string if {\it ch} is not found.
571
572
573\membersection{wxString::c\_str}\label{wxstringcstr}
574
575\constfunc{const wxChar *}{c\_str}{\void}
576
577Returns a pointer to the string data ({\tt const char*} in ANSI build,
578{\tt const wchar\_t*} in Unicode build).
579
580Note that the returned value is not convertible to {\tt char*} or
581{\tt wchar\_t*}, use \helpref{char\_str}{wxstringcharstr} or
582\helpref{wchar\_string}{wxstringwcharstr} if you need to pass string value
583to a function expecting non-const pointer.
584
585\wxheading{See also}
586
587\helpref{mb\_str}{wxstringmbstr}, \helpref{wc\_str}{wxstringwcstr},
588\helpref{fn\_str}{wxstringfnstr}, \helpref{char\_str}{wxstringcharstr},
589\helpref{wchar\_string}{wxstringwcharstr}
590
591\membersection{wxString::char\_str}\label{wxstringcharstr}
592
593\constfunc{wxWritableCharBuffer}{char\_str}{\param{const wxMBConv\&}{ conv = wxConvLibc}}
594
595Returns an object with string data that is implicitly convertible to
596{\tt char*} pointer. Note that any change to the returned buffer is lost and so
597this function is only usable for passing strings to legacy libraries that
598don't have const-correct API. Use \helpref{wxStringBuffer}{wxstringbuffer} if
599you want to modify the string.
600
601\wxheading{See also}
602
603\helpref{mb\_str}{wxstringmbstr}, \helpref{wc\_str}{wxstringwcstr},
604\helpref{fn\_str}{wxstringfnstr}, \helpref{c\_str}{wxstringcstr},
605\helpref{wchar\_str}{wxstringwcharstr}
606
607
608\membersection{wxString::Clear}\label{wxstringclear}
609
610\func{void}{Clear}{\void}
611
612Empties the string and frees memory occupied by it.
613
614See also: \helpref{Empty}{wxstringempty}
615
616
617\membersection{wxString::Cmp}\label{wxstringcmp}
618
619\constfunc{int}{Cmp}{\param{const wxString\&}{ s}}
620
621\constfunc{int}{Cmp}{\param{const wxChar*}{ psz}}
622
623Case-sensitive comparison.
624
625Returns a positive value if the string is greater than the argument, zero if
626it is equal to it or a negative value if it is less than the argument (same semantics
627as the standard {\it strcmp()} function).
628
629See also \helpref{CmpNoCase}{wxstringcmpnocase}, \helpref{IsSameAs}{wxstringissameas}.
630
631
632\membersection{wxString::CmpNoCase}\label{wxstringcmpnocase}
633
634\constfunc{int}{CmpNoCase}{\param{const wxString\&}{ s}}
635
636\constfunc{int}{CmpNoCase}{\param{const wxChar*}{ psz}}
637
638Case-insensitive comparison.
639
640Returns a positive value if the string is greater than the argument, zero if
641it is equal to it or a negative value if it is less than the argument (same semantics
642as the standard {\it strcmp()} function).
643
644See also \helpref{Cmp}{wxstringcmp}, \helpref{IsSameAs}{wxstringissameas}.
645
646
647\membersection{wxString::CompareTo}\label{wxstringcompareto}
648
649\begin{verbatim}
650enum wxString::caseCompare {exact, ignoreCase};
651\end{verbatim}
652
653\constfunc{int}{CompareTo}{\param{const wxChar*}{ psz}, \param{caseCompare}{ cmp = exact}}
654
655Case-sensitive comparison. Returns 0 if equal, 1 if greater or -1 if less.
656
657This is a wxWidgets 1.xx compatibility function; use \helpref{Cmp}{wxstringcmp} instead.
658
659
660\membersection{wxString::Contains}\label{wxstringcontains}
661
662\constfunc{bool}{Contains}{\param{const wxString\&}{ str}}
663
664Returns \true if target appears anywhere in wxString; else \false.
665
666This is a wxWidgets 1.xx compatibility function; you should not use it in new code.
667
668
669\membersection{wxString::Empty}\label{wxstringempty}
670
671\func{void}{Empty}{\void}
672
673Makes the string empty, but doesn't free memory occupied by the string.
674
675See also: \helpref{Clear()}{wxstringclear}.
676
677
678\membersection{wxString::Find}\label{wxstringfind}
679
680\constfunc{int}{Find}{\param{wxUniChar}{ ch}, \param{bool}{ fromEnd = false}}
681
682Searches for the given character. Returns the starting index, or {\tt wxNOT\_FOUND} if not found.
683
684\constfunc{int}{Find}{\param{const wxString\&}{ sub}}
685
686Searches for the given string. Returns the starting index, or {\tt wxNOT\_FOUND} if not found.
687
688
689\membersection{wxString::First}\label{wxstringfirst}
690
691\func{int}{First}{\param{wxChar}{ c}}
692
693\constfunc{int}{First}{\param{const wxChar*}{ psz}}
694
695\constfunc{int}{First}{\param{const wxString\&}{ str}}
696
697Same as \helpref{Find}{wxstringfind}.
698
699This is a wxWidgets 1.xx compatibility function; you should not use it in new code.
700
701
702\membersection{wxString::fn\_str}\label{wxstringfnstr}
703
704\constfunc{const wchar\_t*}{fn\_str}{\void}
705
706\constfunc{const char*}{fn\_str}{\void}
707
708\constfunc{const wxCharBuffer}{fn\_str}{\void}
709
710Returns string representation suitable for passing to OS' functions for
711file handling. In ANSI build, this is same as \helpref{c\_str}{wxstringcstr}.
712In Unicode build, returned value can be either wide character string
713or C string in charset matching the {\tt wxConvFileName} object, depending on
714the OS.
715
716\wxheading{See also}
717
718\helpref{wxMBConv}{wxmbconv},
719\helpref{wc\_str}{wxstringwcstr}, \helpref{mb\_str}{wxstringwcstr}
720
721
722\membersection{wxString::Format}\label{wxstringformat}
723
724\func{static wxString}{Format}{\param{const wxChar }{*format}, \param{}{...}}
725
726This static function returns the string containing the result of calling
727\helpref{Printf}{wxstringprintf} with the passed parameters on it.
728
729\wxheading{See also}
730
731\helpref{FormatV}{wxstringformatv}, \helpref{Printf}{wxstringprintf}
732
733
734\membersection{wxString::FormatV}\label{wxstringformatv}
735
736\func{static wxString}{FormatV}{\param{const wxChar }{*format}, \param{va\_list }{argptr}}
737
738This static function returns the string containing the result of calling
739\helpref{PrintfV}{wxstringprintfv} with the passed parameters on it.
740
741\wxheading{See also}
742
743\helpref{Format}{wxstringformat}, \helpref{PrintfV}{wxstringprintfv}
744
745
746\membersection{wxString::Freq}\label{wxstringfreq}
747
748\constfunc{int}{Freq}{\param{wxChar }{ch}}
749
750Returns the number of occurrences of {\it ch} in the string.
751
752This is a wxWidgets 1.xx compatibility function; you should not use it in new code.
753
754\membersection{wxString::From8BitData}\label{wxstringfrom8bitdata}
755
756\func{static wxString }{From8BitData}{\param{const char*}{ buf}, \param{size\_t}{len}}
757
758\func{static wxString }{From8BitData}{\param{const char*}{ buf}}
759
760Converts given buffer of binary data from 8-bit string to wxString. In Unicode
761build, the string is interpreted as being in ISO-8859-1 encoding. The version
762without \arg{len} parameter takes NUL-terminated data.
763
764This is a convenience method useful when storing binary data in wxString.
765
766\newsince{2.8.4}
767
768\wxheading{See also}
769
770\helpref{To8BitData}{wxstringto8bitdata}
771
772
773\membersection{wxString::FromAscii}\label{wxstringfromascii}
774
775\func{static wxString }{FromAscii}{\param{const char*}{ s}}
776
777\func{static wxString }{FromAscii}{\param{const unsigned char*}{ s}}
778
779\func{static wxString }{FromAscii}{\param{const char*}{ s}, \param{size\_t}{ len}}
780
781\func{static wxString }{FromAscii}{\param{const unsigned char*}{ s}, \param{size\_t}{ len}}
782
783\func{static wxString }{FromAscii}{\param{char}{ c}}
784
785Converts the string or character from an ASCII, 7-bit form
786to the native wxString representation. Most useful when using
787a Unicode build of wxWidgets (note the use of {\tt char} instead of {\tt wxChar}).
788Use \helpref{wxString constructors}{wxstringconstruct} if you
789need to convert from another charset.
790
791
792\membersection{wxString::FromUTF8}\label{wxstringfromutf8}
793
794\func{static wxString }{FromUTF8}{\param{const char*}{ s}}
795
796\func{static wxString }{FromUTF8}{\param{const char*}{ s}, \param{size\_t}{ len}}
797
798Converts C string encoded in UTF-8 to wxString.
799
800Note that this method assumes that \arg{s} is a valid UTF-8 sequence and
801doesn't do any validation in release builds, it's validity is only checked in
802debug builds.
803
804
805\membersection{wxString::GetChar}\label{wxstringgetchar}
806
807\constfunc{wxChar}{GetChar}{\param{size\_t}{ n}}
808
809Returns the character at position {\it n} (read-only).
810
811
812\membersection{wxString::GetData}\label{wxstringgetdata}
813
814\constfunc{const wxChar*}{GetData}{\void}
815
816wxWidgets compatibility conversion. Returns a constant pointer to the data in the string.
817
818
819\membersection{wxString::GetWritableChar}\label{wxstringgetwritablechar}
820
821\func{wxChar\&}{GetWritableChar}{\param{size\_t}{ n}}
822
823Returns a reference to the character at position {\it n}.
824
825
826\membersection{wxString::GetWriteBuf}\label{wxstringgetwritebuf}
827
828\func{wxChar*}{GetWriteBuf}{\param{size\_t}{ len}}
829
830Returns a writable buffer of at least {\it len} bytes.
831It returns a pointer to a new memory block, and the
832existing data will not be copied.
833
834Call \helpref{wxString::UngetWriteBuf}{wxstringungetwritebuf} as soon as
835possible to put the string back into a reasonable state.
836
837This method is deprecated, please use
838\helpref{wxStringBuffer}{wxstringbuffer} or
839\helpref{wxStringBufferLength}{wxstringbufferlength} instead.
840
841
842\membersection{wxString::Index}\label{wxstringindex}
843
844\constfunc{size\_t}{Index}{\param{wxChar}{ ch}}
845
846\constfunc{size\_t}{Index}{\param{const wxChar*}{ sz}}
847
848Same as \helpref{wxString::Find}{wxstringfind}.
849
850This is a wxWidgets 1.xx compatibility function; you should not use it in new code.
851
852
853\membersection{wxString::IsAscii}\label{wxstringisascii}
854
855\constfunc{bool}{IsAscii}{\void}
856
857Returns \true if the string contains only ASCII characters.
858
859This is a wxWidgets 1.xx compatibility function; you should not use it in new code.
860
861
862\membersection{wxString::IsEmpty}\label{wxstringisempty}
863
864\constfunc{bool}{IsEmpty}{\void}
865
866Returns \true if the string is empty.
867
868
869\membersection{wxString::IsNull}\label{wxstringisnull}
870
871\constfunc{bool}{IsNull}{\void}
872
873Returns \true if the string is empty (same as \helpref{IsEmpty}{wxstringisempty}).
874
875This is a wxWidgets 1.xx compatibility function; you should not use it in new code.
876
877
878\membersection{wxString::IsNumber}\label{wxstringisnumber}
879
880\constfunc{bool}{IsNumber}{\void}
881
882Returns \true if the string is an integer (with possible sign).
883
884This is a wxWidgets 1.xx compatibility function; you should not use it in new code.
885
886
887\membersection{wxString::IsSameAs}\label{wxstringissameas}
888
889\constfunc{bool}{IsSameAs}{\param{const wxChar*}{ psz}, \param{bool}{ caseSensitive = true}}
890
891Test for string equality, case-sensitive (default) or not.
892
893caseSensitive is \true by default (case matters).
894
895Returns \true if strings are equal, \false otherwise.
896
897See also \helpref{Cmp}{wxstringcmp}, \helpref{CmpNoCase}{wxstringcmpnocase}
898
899\constfunc{bool}{IsSameAs}{\param{wxChar}{ c}, \param{bool}{ caseSensitive = true}}
900
901Test whether the string is equal to the single character {\it c}. The test is
902case-sensitive if {\it caseSensitive} is \true (default) or not if it is \false.
903
904Returns \true if the string is equal to the character, \false otherwise.
905
906See also \helpref{Cmp}{wxstringcmp}, \helpref{CmpNoCase}{wxstringcmpnocase}
907
908
909\membersection{wxString::IsWord}\label{wxstringisword}
910
911\constfunc{bool}{IsWord}{\void}
912
913Returns \true if the string is a word.
914
915This is a wxWidgets 1.xx compatibility function; you should not use it in new code.
916
917
918\membersection{wxString::Last}\label{wxstringlast}
919
920\constfunc{wxChar}{Last}{\void}
921
922Returns the last character.
923
924\func{wxChar\&}{Last}{\void}
925
926Returns a reference to the last character (writable).
927
928This is a wxWidgets 1.xx compatibility function; you should not use it in new code.
929
930
931\membersection{wxString::Left}\label{wxstringleft}
932
933\constfunc{wxString}{Left}{\param{size\_t}{ count}}
934
935Returns the first {\it count} characters of the string.
936
937
938\membersection{wxString::Len}\label{wxstringlen}
939
940\constfunc{size\_t}{Len}{\void}
941
942Returns the length of the string.
943
944
945\membersection{wxString::Length}\label{wxstringlength}
946
947\constfunc{size\_t}{Length}{\void}
948
949Returns the length of the string (same as Len).
950
951This is a wxWidgets 1.xx compatibility function; you should not use it in new code.
952
953
954\membersection{wxString::Lower}\label{wxstringlower}
955
956\constfunc{wxString}{Lower}{\void}
957
958Returns this string converted to the lower case.
959
960
961\membersection{wxString::LowerCase}\label{wxstringlowercase}
962
963\func{void}{LowerCase}{\void}
964
965Same as MakeLower.
966
967This is a wxWidgets 1.xx compatibility function; you should not use it in new code.
968
969
970\membersection{wxString::MakeLower}\label{wxstringmakelower}
971
972\func{wxString\&}{MakeLower}{\void}
973
974Converts all characters to lower case and returns the result.
975
976
977\membersection{wxString::MakeUpper}\label{wxstringmakeupper}
978
979\func{wxString\&}{MakeUpper}{\void}
980
981Converts all characters to upper case and returns the result.
982
983
984\membersection{wxString::Matches}\label{wxstringmatches}
985
986\constfunc{bool}{Matches}{\param{const wxString\&}{ mask}}
987
988Returns \true if the string contents matches a mask containing '*' and '?'.
989
990
991\membersection{wxString::mb\_str}\label{wxstringmbstr}
992
993\constfunc{const char*}{mb\_str}{\param{const wxMBConv\&}{ conv = wxConvLibc}}
994
995\constfunc{const wxCharBuffer}{mb\_str}{\param{const wxMBConv\&}{ conv = wxConvLibc}}
996
997Returns multibyte (C string) representation of the string.
998In Unicode build, converts using \arg{conv}'s \helpref{cWC2MB}{wxmbconvcwc2mb}
999method and returns wxCharBuffer. In ANSI build, this function is same
1000as \helpref{c\_str}{wxstringcstr}.
1001The macro wxWX2MBbuf is defined as the correct return type (without const).
1002
1003\wxheading{See also}
1004
1005\helpref{wxMBConv}{wxmbconv},
1006\helpref{c\_str}{wxstringcstr}, \helpref{wc\_str}{wxstringwcstr},
1007\helpref{fn\_str}{wxstringfnstr}, \helpref{char\_str}{wxstringcharstr}
1008
1009
1010\membersection{wxString::Mid}\label{wxstringmid}
1011
1012\constfunc{wxString}{Mid}{\param{size\_t}{ first}, \param{size\_t}{ count = wxSTRING\_MAXLEN}}
1013
1014Returns a substring starting at {\it first}, with length {\it count}, or the rest of
1015the string if {\it count} is the default value.
1016
1017
1018\membersection{wxString::Pad}\label{wxstringpad}
1019
1020\func{wxString\&}{Pad}{\param{size\_t}{ count}, \param{wxChar}{ pad = ' '}, \param{bool}{ fromRight = true}}
1021
1022Adds {\it count} copies of {\it pad} to the beginning, or to the end of the string (the default).
1023
1024Removes spaces from the left or from the right (default).
1025
1026
1027\membersection{wxString::Prepend}\label{wxstringprepend}
1028
1029\func{wxString\&}{Prepend}{\param{const wxString\&}{ str}}
1030
1031Prepends {\it str} to this string, returning a reference to this string.
1032
1033
1034\membersection{wxString::Printf}\label{wxstringprintf}
1035
1036\func{int}{Printf}{\param{const wxChar* }{pszFormat}, \param{}{...}}
1037
1038Similar to the standard function {\it sprintf()}. Returns the number of
1039characters written, or an integer less than zero on error.
1040
1041Note that if {\tt wxUSE\_PRINTF\_POS\_PARAMS} is set to 1, then this function supports
1042Unix98-style positional parameters:
1043
1044\begin{verbatim}
1045 wxString str;
1046
1047 str.Printf(wxT("%d %d %d"), 1, 2, 3);
1048 // str now contains "1 2 3"
1049
1050 str.Printf(wxT("%2$d %3$d %1$d"), 1, 2, 3);
1051 // str now contains "2 3 1"
1052\end{verbatim}
1053
1054{\bf NB:} This function will use a safe version of {\it vsprintf()} (usually called
1055{\it vsnprintf()}) whenever available to always allocate the buffer of correct
1056size. Unfortunately, this function is not available on all platforms and the
1057dangerous {\it vsprintf()} will be used then which may lead to buffer overflows.
1058
1059
1060\membersection{wxString::PrintfV}\label{wxstringprintfv}
1061
1062\func{int}{PrintfV}{\param{const wxChar* }{pszFormat}, \param{va\_list}{ argPtr}}
1063
1064Similar to vprintf. Returns the number of characters written, or an integer less than zero
1065on error.
1066
1067
1068\membersection{wxString::Remove}\label{wxstringremove}
1069
1070\func{wxString\&}{Remove}{\param{size\_t}{ pos}}
1071
1072Same as Truncate. Removes the portion from {\it pos} to the end of the string.
1073
1074\func{wxString\&}{Remove}{\param{size\_t}{ pos}, \param{size\_t}{ len}}
1075
1076Removes {\it len} characters from the string, starting at {\it pos}.
1077
1078This is a wxWidgets 1.xx compatibility function; you should not use it in new code.
1079
1080
1081\membersection{wxString::RemoveLast}\label{wxstringremovelast}
1082
1083\func{wxString\&}{RemoveLast}{\void}
1084
1085Removes the last character.
1086
1087
1088\membersection{wxString::Replace}\label{wxstringreplace}
1089
1090\func{size\_t}{Replace}{\param{const wxString\&}{ strOld}, \param{const wxString\&}{ strNew}, \param{bool}{ replaceAll = true}}
1091
1092Replace first (or all) occurrences of substring with another one.
1093
1094{\it replaceAll}: global replace (default), or only the first occurrence.
1095
1096Returns the number of replacements made.
1097
1098
1099\membersection{wxString::Right}\label{wxstringright}
1100
1101\constfunc{wxString}{Right}{\param{size\_t}{ count}}
1102
1103Returns the last {\it count} characters.
1104
1105
1106\membersection{wxString::SetChar}\label{wxstringsetchar}
1107
1108\func{void}{SetChar}{\param{size\_t}{ n}, \param{wxChar}{ch}}
1109
1110Sets the character at position {\it n}.
1111
1112
1113\membersection{wxString::Shrink}\label{wxstringshrink}
1114
1115\func{void}{Shrink}{\void}
1116
1117Minimizes the string's memory. This can be useful after a call to
1118\helpref{Alloc()}{wxstringalloc} if too much memory were preallocated.
1119
1120
1121\membersection{wxString::StartsWith}\label{wxstringstartswith}
1122
1123\constfunc{bool}{StartsWith}{\param{const wxString\& }{prefix}, \param{wxString }{*rest = NULL}}
1124
1125This function can be used to test if the string starts with the specified
1126{\it prefix}. If it does, the function will return \true and put the rest
1127of the string (i.e. after the prefix) into {\it rest} string if it is not
1128{\tt NULL}. Otherwise, the function returns \false and doesn't modify the
1129{\it rest}.
1130
1131
1132\membersection{wxString::EndsWith}\label{wxstringendswith}
1133
1134\constfunc{bool}{EndsWith}{\param{const wxString\& }{suffix}, \param{wxString }{*rest = NULL}}
1135
1136This function can be used to test if the string ends with the specified
1137{\it suffix}. If it does, the function will return \true and put the
1138beginning of the string before the suffix into {\it rest} string if it is not
1139{\tt NULL}. Otherwise, the function returns \false and doesn't
1140modify the {\it rest}.
1141
1142
1143\membersection{wxString::Strip}\label{wxstringstrip}
1144
1145\begin{verbatim}
1146enum wxString::stripType {leading = 0x1, trailing = 0x2, both = 0x3};
1147\end{verbatim}
1148
1149\constfunc{wxString}{Strip}{\param{stripType}{ s = trailing}}
1150
1151Strip characters at the front and/or end. The same as Trim except that it
1152doesn't change this string.
1153
1154This is a wxWidgets 1.xx compatibility function; you should not use it in new code.
1155
1156
1157\membersection{wxString::SubString}\label{wxstringsubstring}
1158
1159\constfunc{wxString}{SubString}{\param{size\_t}{ from}, \param{size\_t}{ to}}
1160
1161Returns the part of the string between the indices {\it from} and {\it to}
1162inclusive.
1163
1164This is a wxWidgets 1.xx compatibility function, use \helpref{Mid}{wxstringmid}
1165instead (but note that parameters have different meaning).
1166
1167
1168\membersection{wxString::To8BitData}\label{wxstringto8bitdata}
1169
1170\constfunc{const char*}{To8BitData}{\void}
1171
1172Converts the string to an 8-bit string (ANSI builds only).
1173
1174\constfunc{const wxCharBuffer}{To8BitData}{\void}
1175
1176Converts the string to an 8-bit string in ISO-8859-1 encoding in the form of
1177a wxCharBuffer (Unicode builds only).
1178
1179This is a convenience method useful when storing binary data in wxString.
1180
1181\newsince{2.8.4}
1182
1183\wxheading{See also}
1184
1185\helpref{From8BitData}{wxstringfrom8bitdata}
1186
1187
1188\membersection{wxString::ToAscii}\label{wxstringtoascii}
1189
1190\constfunc{const char*}{ToAscii}{\void}
1191
1192\constfunc{const wxCharBuffer}{ToAscii}{\void}
1193
1194Converts the string to an ASCII, 7-bit string in the form of
1195a wxCharBuffer (Unicode builds only) or a C string (ANSI builds).
1196
1197Note that this conversion only works if the string contains only ASCII
1198characters. The \helpref{mb\_str}{wxstringmbstr} method provides more
1199powerful means of converting wxString to C string.
1200
1201
1202\membersection{wxString::ToDouble}\label{wxstringtodouble}
1203
1204\constfunc{bool}{ToDouble}{\param{double}{ *val}}
1205
1206Attempts to convert the string to a floating point number. Returns \true on
1207success (the number is stored in the location pointed to by {\it val}) or \false
1208if the string does not represent such number.
1209
1210\wxheading{See also}
1211
1212\helpref{wxString::ToLong}{wxstringtolong},\\
1213\helpref{wxString::ToULong}{wxstringtoulong}
1214
1215
1216\membersection{wxString::ToLong}\label{wxstringtolong}
1217
1218\constfunc{bool}{ToLong}{\param{long}{ *val}, \param{int }{base = $10$}}
1219
1220Attempts to convert the string to a signed integer in base {\it base}. Returns
1221\true on success in which case the number is stored in the location
1222pointed to by {\it val} or \false if the string does not represent a
1223valid number in the given base.
1224
1225The value of {\it base} must be comprised between $2$ and $36$, inclusive, or
1226be a special value $0$ which means that the usual rules of {\tt C} numbers are
1227applied: if the number starts with {\tt 0x} it is considered to be in base
1228$16$, if it starts with {\tt 0} - in base $8$ and in base $10$ otherwise. Note
1229that you may not want to specify the base $0$ if you are parsing the numbers
1230which may have leading zeroes as they can yield unexpected (to the user not
1231familiar with C) results.
1232
1233\wxheading{See also}
1234
1235\helpref{wxString::ToDouble}{wxstringtodouble},\\
1236\helpref{wxString::ToULong}{wxstringtoulong}
1237
1238
1239\membersection{wxString::ToLongLong}\label{wxstringtolonglong}
1240
1241\constfunc{bool}{ToLongLong}{\param{wxLongLong\_t}{ *val}, \param{int }{base = $10$}}
1242
1243This is exactly the same as \helpref{ToLong}{wxstringtolong} but works with 64
1244bit integer numbers.
1245
1246Notice that currently it doesn't work (always returns \false) if parsing of 64
1247bit numbers is not supported by the underlying C run-time library. Compilers
1248with C99 support and Microsoft Visual C++ version 7 and higher do support this.
1249
1250\wxheading{See also}
1251
1252\helpref{wxString::ToLong}{wxstringtolong},\\
1253\helpref{wxString::ToULongLong}{wxstringtoulonglong}
1254
1255
1256\membersection{wxString::ToULong}\label{wxstringtoulong}
1257
1258\constfunc{bool}{ToULong}{\param{unsigned long}{ *val}, \param{int }{base = $10$}}
1259
1260Attempts to convert the string to an unsigned integer in base {\it base}.
1261Returns \true on success in which case the number is stored in the
1262location pointed to by {\it val} or \false if the string does not
1263represent a valid number in the given base. Please notice that this function
1264behaves in the same way as the standard \texttt{strtoul()} and so it simply
1265converts negative numbers to unsigned representation instead of rejecting them
1266(e.g. $-1$ is returned as \texttt{ULONG\_MAX}).
1267
1268See \helpref{wxString::ToLong}{wxstringtolong} for the more detailed
1269description of the {\it base} parameter.
1270
1271\wxheading{See also}
1272
1273\helpref{wxString::ToDouble}{wxstringtodouble},\\
1274\helpref{wxString::ToLong}{wxstringtolong}
1275
1276
1277\membersection{wxString::ToULongLong}\label{wxstringtoulonglong}
1278
1279\constfunc{bool}{ToULongLong}{\param{wxULongLong\_t}{ *val}, \param{int }{base = $10$}}
1280
1281This is exactly the same as \helpref{ToULong}{wxstringtoulong} but works with 64
1282bit integer numbers.
1283
1284Please see \helpref{ToLongLong}{wxstringtolonglong} for additional remarks.
1285
1286
1287\membersection{wxString::ToUTF8}\label{wxstringtoutf8}
1288
1289\constfunc{const char*}{ToUTF8}{\void}
1290
1291\constfunc{const wxCharBuffer}{ToUF8}{\void}
1292
1293Same as \helpref{utf8\_str}{wxstringutf8str}.
1294
1295
1296\membersection{wxString::Trim}\label{wxstringtrim}
1297
1298\func{wxString\&}{Trim}{\param{bool}{ fromRight = true}}
1299
1300Removes white-space (space, tabs, form feed, newline and carriage return) from
1301the left or from the right end of the string (right is default).
1302
1303
1304\membersection{wxString::Truncate}\label{wxstringtruncate}
1305
1306\func{wxString\&}{Truncate}{\param{size\_t}{ len}}
1307
1308Truncate the string to the given length.
1309
1310
1311\membersection{wxString::UngetWriteBuf}\label{wxstringungetwritebuf}
1312
1313\func{void}{UngetWriteBuf}{\void}
1314
1315\func{void}{UngetWriteBuf}{\param{size\_t }{len}}
1316
1317Puts the string back into a reasonable state (in which it can be used
1318normally), after
1319\rtfsp\helpref{wxString::GetWriteBuf}{wxstringgetwritebuf} was called.
1320
1321The version of the function without the {\it len} parameter will calculate the
1322new string length itself assuming that the string is terminated by the first
1323{\tt NUL} character in it while the second one will use the specified length
1324and thus is the only version which should be used with the strings with
1325embedded {\tt NUL}s (it is also slightly more efficient as {\tt strlen()}
1326doesn't have to be called).
1327
1328This method is deprecated, please use
1329\helpref{wxStringBuffer}{wxstringbuffer} or
1330\helpref{wxStringBufferLength}{wxstringbufferlength} instead.
1331
1332
1333\membersection{wxString::Upper}\label{wxstringupper}
1334
1335\constfunc{wxString}{Upper}{\void}
1336
1337Returns this string converted to upper case.
1338
1339
1340\membersection{wxString::UpperCase}\label{wxstringuppercase}
1341
1342\func{void}{UpperCase}{\void}
1343
1344The same as MakeUpper.
1345
1346This is a wxWidgets 1.xx compatibility function; you should not use it in new code.
1347
1348
1349\membersection{wxString::utf8\_str}\label{wxstringutf8str}
1350
1351\constfunc{const char*}{utf8\_str}{\void}
1352
1353\constfunc{const wxCharBuffer}{utf8\_str}{\void}
1354
1355Converts the strings contents to UTF-8 and returns it either as a temporary
1356wxCharBuffer object or as a pointer to the internal string contents in
1357UTF-8 build.
1358% FIXME-UTF8: link to a topic explaining UTF-8 build here
1359
1360
1361\membersection{wxString::wc\_str}\label{wxstringwcstr}
1362
1363\constfunc{const wchar\_t*}{wc\_str}{\param{const wxMBConv\&}{ conv}}
1364
1365\constfunc{const wxWCharBuffer}{wc\_str}{\param{const wxMBConv\&}{ conv}}
1366
1367Returns wide character representation of the string.
1368In ANSI build, converts using \arg{conv}'s \helpref{cMB2WC}{wxmbconvcmb2wc}
1369method and returns wxWCharBuffer. In Unicode build, this function is same
1370as \helpref{c\_str}{wxstringcstr}.
1371The macro wxWX2WCbuf is defined as the correct return type (without const).
1372
1373\wxheading{See also}
1374
1375\helpref{wxMBConv}{wxmbconv},
1376\helpref{c\_str}{wxstringcstr}, \helpref{mb\_str}{wxstringwcstr},
1377\helpref{fn\_str}{wxstringfnstr}, \helpref{wchar\_str}{wxstringwcharstr}
1378
1379\membersection{wxString::wchar\_str}\label{wxstringwcharstr}
1380
1381\constfunc{wxWritableWCharBuffer}{wchar\_str}{\void}
1382
1383Returns an object with string data that is implicitly convertible to
1384{\tt char*} pointer. Note that changes to the returned buffer may or may
1385not be lost (depending on the build) and so this function is only usable for
1386passing strings to legacy libraries that don't have const-correct API. Use
1387\helpref{wxStringBuffer}{wxstringbuffer} if you want to modify the string.
1388
1389\wxheading{See also}
1390
1391\helpref{mb\_str}{wxstringmbstr}, \helpref{wc\_str}{wxstringwcstr},
1392\helpref{fn\_str}{wxstringfnstr}, \helpref{c\_str}{wxstringcstr},
1393\helpref{char\_str}{wxstringcharstr}
1394
1395
1396\membersection{wxString::operator!}\label{wxstringoperatornot}
1397
1398\constfunc{bool}{operator!}{\void}
1399
1400Empty string is \false, so !string will only return \true if the string is empty.
1401This allows the tests for NULLness of a {\it const wxChar *} pointer and emptiness
1402of the string to look the same in the code and makes it easier to port old code
1403to wxString.
1404
1405See also \helpref{IsEmpty()}{wxstringisempty}.
1406
1407
1408\membersection{wxString::operator $=$}\label{wxstringoperatorassign}
1409
1410\func{wxString\&}{operator $=$}{\param{const wxString\&}{ str}}
1411
1412\func{wxString\&}{operator $=$}{\param{const wxChar*}{ psz}}
1413
1414\func{wxString\&}{operator $=$}{\param{wxChar}{ c}}
1415
1416Assignment: the effect of each operation is the same as for the corresponding
1417constructor (see \helpref{wxString constructors}{wxstringconstruct}).
1418
1419
1420\membersection{wxString::operator $+$}\label{wxstringoperatorplus}
1421
1422Concatenation: all these operators return a new string equal to the
1423concatenation of the operands.
1424
1425\func{wxString}{operator $+$}{\param{const wxString\&}{ x}, \param{const wxString\&}{ y}}
1426
1427\func{wxString}{operator $+$}{\param{const wxString\&}{ x}, \param{const wxChar*}{ y}}
1428
1429\func{wxString}{operator $+$}{\param{const wxString\&}{ x}, \param{wxChar}{ y}}
1430
1431\func{wxString}{operator $+$}{\param{const wxChar*}{ x}, \param{const wxString\&}{ y}}
1432
1433
1434\membersection{wxString::operator $+=$}\label{wxstringplusequal}
1435
1436\func{void}{operator $+=$}{\param{const wxString\&}{ str}}
1437
1438\func{void}{operator $+=$}{\param{const wxChar*}{ psz}}
1439
1440\func{void}{operator $+=$}{\param{wxChar}{ c}}
1441
1442Concatenation in place: the argument is appended to the string.
1443
1444
1445\membersection{wxString::operator []}\label{wxstringoperatorbracket}
1446
1447\func{wxChar\&}{operator []}{\param{size\_t}{ i}}
1448
1449\constfunc{wxChar}{operator []}{\param{size\_t}{ i}}
1450
1451\func{wxChar\&}{operator []}{\param{int}{ i}}
1452
1453\constfunc{wxChar}{operator []}{\param{int}{ i}}
1454
1455Element extraction.
1456
1457
1458\membersection{wxString::operator ()}\label{wxstringoperatorparenth}
1459
1460\func{wxString}{operator ()}{\param{size\_t}{ start}, \param{size\_t}{ len}}
1461
1462Same as Mid (substring extraction).
1463
1464
1465\membersection{wxString::operator \cinsert}\label{wxstringoperatorout}
1466
1467\func{wxString\&}{operator \cinsert}{\param{const wxString\&}{ str}}
1468
1469\func{wxString\&}{operator \cinsert}{\param{const wxChar*}{ psz}}
1470
1471\func{wxString\&}{operator \cinsert}{\param{wxChar }{ch}}
1472
1473Same as $+=$.
1474
1475\func{wxString\&}{operator \cinsert}{\param{int}{ i}}
1476
1477\func{wxString\&}{operator \cinsert}{\param{float}{ f}}
1478
1479\func{wxString\&}{operator \cinsert}{\param{double}{ d}}
1480
1481These functions work as C++ stream insertion operators: they insert the given
1482value into the string. Precision or format cannot be set using them, you can use
1483\helpref{Printf}{wxstringprintf} for this.
1484
1485
1486\membersection{wxString::operator \cextract}\label{wxstringoperatorin}
1487
1488\func{friend istream\&}{operator \cextract}{\param{istream\&}{ is}, \param{wxString\&}{ str}}
1489
1490Extraction from a stream.
1491
1492
1493\membersection{wxString::operator const wxChar*}\label{wxstringoperatorconstcharpt}
1494
1495\constfunc{}{operator const wxChar*}{\void}
1496
1497Implicit conversion to a C string.
1498
1499
1500\membersection{Comparison operators}\label{wxstringcomparison}
1501
1502\func{bool}{operator $==$}{\param{const wxString\&}{ x}, \param{const wxString\&}{ y}}
1503
1504\func{bool}{operator $==$}{\param{const wxString\&}{ x}, \param{const wxChar*}{ t}}
1505
1506\func{bool}{operator $!=$}{\param{const wxString\&}{ x}, \param{const wxString\&}{ y}}
1507
1508\func{bool}{operator $!=$}{\param{const wxString\&}{ x}, \param{const wxChar*}{ t}}
1509
1510\func{bool}{operator $>$}{\param{const wxString\&}{ x}, \param{const wxString\&}{ y}}
1511
1512\func{bool}{operator $>$}{\param{const wxString\&}{ x}, \param{const wxChar*}{ t}}
1513
1514\func{bool}{operator $>=$}{\param{const wxString\&}{ x}, \param{const wxString\&}{ y}}
1515
1516\func{bool}{operator $>=$}{\param{const wxString\&}{ x}, \param{const wxChar*}{ t}}
1517
1518\func{bool}{operator $<$}{\param{const wxString\&}{ x}, \param{const wxString\&}{ y}}
1519
1520\func{bool}{operator $<$}{\param{const wxString\&}{ x}, \param{const wxChar*}{ t}}
1521
1522\func{bool}{operator $<=$}{\param{const wxString\&}{ x}, \param{const wxString\&}{ y}}
1523
1524\func{bool}{operator $<=$}{\param{const wxString\&}{ x}, \param{const wxChar*}{ t}}
1525
1526\wxheading{Remarks}
1527
1528These comparisons are case-sensitive.
1529
1530
1531\section{\class{wxStringBuffer}}\label{wxstringbuffer}
1532
1533This tiny class allows to conveniently access the \helpref{wxString}{wxstring}
1534internal buffer as a writable pointer without any risk of forgetting to restore
1535the string to the usable state later.
1536
1537For example, assuming you have a low-level OS function called
1538{\tt GetMeaningOfLifeAsString(char *)} returning the value in the provided
1539buffer (which must be writable, of course) you might call it like this:
1540
1541\begin{verbatim}
1542 wxString theAnswer;
1543 GetMeaningOfLifeAsString(wxStringBuffer(theAnswer, 1024));
1544 if ( theAnswer != "42" )
1545 {
1546 wxLogError("Something is very wrong!");
1547 }
1548\end{verbatim}
1549
1550Note that the exact usage of this depends on whether on not wxUSE\_STL is enabled. If
1551wxUSE\_STL is enabled, wxStringBuffer creates a separate empty character buffer, and
1552if wxUSE\_STL is disabled, it uses GetWriteBuf() from wxString, keeping the same buffer
1553wxString uses intact. In other words, relying on wxStringBuffer containing the old
1554wxString data is probably not a good idea if you want to build your program in both
1555with and without wxUSE\_STL.
1556
1557\wxheading{Derived from}
1558
1559None
1560
1561\wxheading{Include files}
1562
1563<wx/string.h>
1564
1565\latexignore{\rtfignore{\wxheading{Members}}}
1566
1567
1568\membersection{wxStringBuffer::wxStringBuffer}\label{wxstringbufferctor}
1569
1570\func{}{wxStringBuffer}{\param{const wxString\& }{str}, \param{size\_t }{len}}
1571
1572Constructs a writable string buffer object associated with the given string
1573and containing enough space for at least {\it len} characters. Basically, this
1574is equivalent to calling \helpref{GetWriteBuf}{wxstringgetwritebuf} and
1575saving the result.
1576
1577
1578\membersection{wxStringBuffer::\destruct{wxStringBuffer}}\label{wxstringbufferdtor}
1579
1580\func{}{\destruct{wxStringBuffer}}{\void}
1581
1582Restores the string passed to the constructor to the usable state by calling
1583\helpref{UngetWriteBuf}{wxstringungetwritebuf} on it.
1584
1585
1586\membersection{wxStringBuffer::operator wxChar *}\label{wxstringbufferwxchar}
1587
1588\func{wxChar *}{operator wxChar *}{\void}
1589
1590Returns the writable pointer to a buffer of the size at least equal to the
1591length specified in the constructor.
1592
1593
1594
1595\section{\class{wxStringBufferLength}}\label{wxstringbufferlength}
1596
1597This tiny class allows to conveniently access the \helpref{wxString}{wxstring}
1598internal buffer as a writable pointer without any risk of forgetting to restore
1599the string to the usable state later, and allows the user to set the internal
1600length of the string.
1601
1602For example, assuming you have a low-level OS function called
1603{\tt int GetMeaningOfLifeAsString(char *)} copying the value in the provided
1604buffer (which must be writable, of course), and returning the actual length
1605of the string, you might call it like this:
1606
1607\begin{verbatim}
1608 wxString theAnswer;
1609 wxStringBuffer theAnswerBuffer(theAnswer, 1024);
1610 int nLength = GetMeaningOfLifeAsString(theAnswerBuffer);
1611 theAnswerBuffer.SetLength(nLength);
1612 if ( theAnswer != "42" )
1613 {
1614 wxLogError("Something is very wrong!");
1615 }
1616\end{verbatim}
1617
1618Note that the exact usage of this depends on whether on not wxUSE\_STL is enabled. If
1619wxUSE\_STL is enabled, wxStringBuffer creates a separate empty character buffer, and
1620if wxUSE\_STL is disabled, it uses GetWriteBuf() from wxString, keeping the same buffer
1621wxString uses intact. In other words, relying on wxStringBuffer containing the old
1622wxString data is probably not a good idea if you want to build your program in both
1623with and without wxUSE\_STL.
1624
1625Note that SetLength {\tt must} be called before wxStringBufferLength destructs.
1626
1627\wxheading{Derived from}
1628
1629None
1630
1631\wxheading{Include files}
1632
1633<wx/string.h>
1634
1635\latexignore{\rtfignore{\wxheading{Members}}}
1636
1637
1638\membersection{wxStringBufferLength::wxStringBufferLength}\label{wxstringbufferlengthctor}
1639
1640\func{}{wxStringBufferLength}{\param{const wxString\& }{str}, \param{size\_t }{len}}
1641
1642Constructs a writable string buffer object associated with the given string
1643and containing enough space for at least {\it len} characters. Basically, this
1644is equivalent to calling \helpref{GetWriteBuf}{wxstringgetwritebuf} and
1645saving the result.
1646
1647
1648\membersection{wxStringBufferLength::\destruct{wxStringBufferLength}}\label{wxstringbufferlengthdtor}
1649
1650\func{}{\destruct{wxStringBufferLength}}{\void}
1651
1652Restores the string passed to the constructor to the usable state by calling
1653\helpref{UngetWriteBuf}{wxstringungetwritebuf} on it.
1654
1655
1656\membersection{wxStringBufferLength::SetLength}\label{wxstringbufferlengthsetlength}
1657
1658\func{void}{SetLength}{\param{size\_t }{nLength}}
1659
1660Sets the internal length of the string referred to by wxStringBufferLength to
1661{\it nLength} characters.
1662
1663Must be called before wxStringBufferLength destructs.
1664
1665
1666\membersection{wxStringBufferLength::operator wxChar *}\label{wxstringbufferlengthwxchar}
1667
1668\func{wxChar *}{operator wxChar *}{\void}
1669
1670Returns the writable pointer to a buffer of the size at least equal to the
1671length specified in the constructor.
1672
1673