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