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