]> git.saurik.com Git - wxWidgets.git/blame - docs/latex/wx/wxstring.tex
Overwrote(!!) with source files that compile and link with latest wxGTK.
[wxWidgets.git] / docs / latex / wx / wxstring.tex
CommitLineData
a660d684
KB
1\section{\class{wxString}}\label{wxstring}
2
b3324be2
JS
3\wxheading{Derived from}
4
5None
a660d684 6
b3324be2
JS
7\wxheading{See also}
8
9\overview{Overview}{wxstringoverview}
a660d684 10
b3324be2 11\latexignore{\rtfignore{\wxheading{Members}}}
a660d684
KB
12
13\membersection{wxString::wxString}\label{wxstringconstruct}
14
b3324be2 15\func{}{wxString}{\void}
a660d684 16
b3324be2 17Default constructor.
a660d684 18
b3324be2 19\func{}{wxString}{\param{const wxString\&}{ x}}
a660d684 20
b3324be2 21Copy constructor.
a660d684 22
b3324be2 23\func{}{wxString}{\param{char}{ ch}, \param{size\_t}{ n = 1}}
a660d684 24
b3324be2 25Constructs a string of {\it n} copies of character {\it ch}.
a660d684 26
b3324be2 27\func{}{wxString}{\param{const char*}{ psz}, \param{size\_t}{ nLength = STRING\_MAXLEN}}
a660d684 28
b3324be2
JS
29Takes first {\it nLength} characters from the C string {\it psz}.
30The default value of STRING\_MAXLEN means take all the string.
a660d684 31
b3324be2 32\func{}{wxString}{\param{const unsigned char*}{ psz}, \param{size\_t}{ nLength = STRING\_MAXLEN}}
a660d684 33
b3324be2
JS
34For compilers using unsigned char: takes first {\it nLength} characters from the C string {\it psz}.
35The default value of STRING\_MAXLEN means take all the string.
a660d684 36
b3324be2 37\func{}{wxString}{\param{const wchar\_t*}{ psz}}
a660d684 38
b3324be2 39Constructs a string from the wide (UNICODE) string.
a660d684 40
b3324be2 41\membersection{wxString::\destruct{wxString}}\label{wxstringdestruct}
a660d684 42
b3324be2 43\func{}{\destruct{wxString}}{\void}
a660d684 44
b3324be2 45String destructor. Note that this is not virtual, so wxString must not be inherited from.
a660d684 46
b3324be2 47\membersection{wxString::Alloc}\label{wxstringAlloc}
a660d684 48
b3324be2 49\func{void}{Alloc}{\param{uint}{ newsize}}
a660d684 50
b3324be2 51Preallocate some space for wxString. Only works if the data of this string is not shared.
a660d684 52
b3324be2
JS
53\membersection{wxString::Append}\label{wxstringAppend}
54
55\func{wxString\&}{Append}{\param{const char*}{ psz}}
a660d684 56
b3324be2 57Concatenates {\it psz} to this string, returning a reference to it.
a660d684 58
b3324be2 59\func{wxString\&}{Append}{\param{char}{ ch}, \param{int}{ count = 1}}
a660d684 60
b3324be2
JS
61Concatenates character {\it ch} to this string, {\it count} times, returning a reference
62to it.
63
64\membersection{wxString::After}\label{wxstringAfter}
65
66\constfunc{wxString}{After}{\param{char}{ ch}}
67
68Gets all the characters after the first occurence of {\it ch}.
69Returns the empty string if {\it ch} is not found.
a660d684
KB
70
71\membersection{wxString::Before}\label{wxstringBefore}
72
b3324be2
JS
73\constfunc{wxString}{Before}{\param{char}{ ch}}
74
75Gets all characters before the last occurence of {\it ch}.
76Returns empty string if {\it ch} is not found.
a660d684 77
f7bd2698
JS
78\membersection{wxString::Cmp}\label{wxstringcmp}
79
80\constfunc{int}{Cmp}{\param{const char*}{ psz}}
81
82Case-sensitive comparison.
83
84Returns 0 if equal, +1 if greater or -1 if less.
85
86See also CmpNoCase, IsSameAs.
87
88\membersection{wxString::CmpNoCase}\label{wxstringcmpnocase}
89
90\constfunc{int}{CmpNoCase}{\param{const char*}{ psz}}
91
92Case-insensitive comparison.
93
94Returns 0 if equal, +1 if greater or -1 if less.
95
96See also Cmp, IsSameAs.
97
a660d684
KB
98\membersection{wxString::CompareTo}\label{wxstringCompareTo}
99
100\begin{verbatim}
101#define NO_POS ((int)(-1)) // undefined position
b3324be2 102enum caseCompare {exact, ignoreCase};
a660d684
KB
103\end{verbatim}
104
b3324be2 105\constfunc{int}{CompareTo}{\param{const char*}{ psz}, \param{caseCompare}{ cmp = exact}}
a660d684 106
b3324be2 107Case-sensitive comparison. Returns 0 if equal, 1 if greater or -1 if less.
a660d684 108
b3324be2 109\membersection{wxString::Contains}\label{wxstringContains}
a660d684 110
b3324be2 111\func{bool}{Contains}{\param{const wxString\&}{ str}}
a660d684 112
b3324be2 113Returns 1 if target appears anyhere in wxString; else 0.
a660d684 114
f7bd2698 115\membersection{wxString::Empty}\label{wxstringempty}
a660d684 116
f7bd2698
JS
117\func{void}{Empty}{\void}
118
119Reinitializes the string and frees the data.
120
121\membersection{wxString::Find}\label{wxstringfind}
122
123\constfunc{int}{Find}{\param{char}{ ch}, \param{bool}{ fromEnd = FALSE}}
124
125Searches for the given character. Returns the starting index, or -1 if not found.
126
127\constfunc{int}{Find}{\param{const char*}{ sz}}
128
129Searches for the given string. Returns the starting index, or -1 if not found.
a660d684 130
b3324be2 131\membersection{wxString::First}\label{wxstringfirst}
a660d684 132
b3324be2 133\func{size\_t}{First}{\param{char}{ c}}
a660d684 134
b3324be2 135\constfunc{size\_t}{First}{\param{const char*}{ psz}}
a660d684 136
b3324be2 137\constfunc{size\_t}{First}{\param{const wxString\&}{ str}}
a660d684 138
b3324be2 139\constfunc{size\_t}{First}{\param{const char}{ ch}}
a660d684 140
f7bd2698 141Returns the first occurrence of the item.
a660d684 142
f7bd2698 143\membersection{wxString::GetChar}\label{wxstringgetchar}
a660d684 144
f7bd2698 145\constfunc{char}{GetChar}{\param{size\_t}{ n}}
a660d684 146
f7bd2698 147Returns the character at position {\it n} (read-only).
a660d684 148
f7bd2698 149\membersection{wxString::GetData}\label{wxstringGetData}
a660d684 150
f7bd2698 151\constfunc{const char*}{GetData}{\void}
a660d684 152
f7bd2698 153wxWindows compatibility conversion. Returns a constant pointer to the data in the string.
a660d684 154
f7bd2698 155\membersection{wxString::GetWritableChar}\label{wxstringgetwritablechar}
a660d684 156
f7bd2698 157\func{char\&}{GetWritableChar}{\param{size\_t}{ n}}
a660d684 158
f7bd2698 159Returns a reference to the character at position {\it n}.
a660d684 160
f7bd2698 161\membersection{wxString::GetWriteBuf}\label{wxstringgetwritebuf}
a660d684 162
f7bd2698 163\func{char*}{GetWriteBuf}{\param{uint}{ len}}
a660d684 164
f7bd2698 165Returns a writable buffer of at least {\it len} bytes.
a660d684 166
f7bd2698
JS
167Call \helpref{wxString::UngetWriteBuf}{wxstringungetwritebuf} as soon as possible
168to put the string back into a reasonable state.
a660d684 169
f7bd2698 170\membersection{wxString::Index}\label{wxstringIndex}
a660d684 171
f7bd2698 172\constfunc{size\_t}{Index}{\param{char}{ ch}, \param{int}{ startpos = 0}}
a660d684 173
f7bd2698 174Same as \helpref{wxString::Find}{wxstringfind}.
a660d684 175
f7bd2698 176\constfunc{size\_t}{Index}{\param{const char*}{ sz}}
a660d684 177
f7bd2698 178Same as \helpref{wxString::Find}{wxstringfind}.
a660d684 179
f7bd2698 180\constfunc{size\_t}{Index}{\param{const char*}{ sz}, \param{bool}{ caseSensitive = TRUE}, \param{bool}{ fromEnd = FALSE}}
a660d684 181
f7bd2698 182Search the element in the array, starting from either side.
a660d684 183
f7bd2698 184If {\it fromEnd} is TRUE, reverse search direction.
a660d684 185
f7bd2698 186If {\bf caseSensitive}, comparison is case sensitive (the default).
a660d684 187
f7bd2698 188Returns the index of the first item matched, or NOT\_FOUND.
a660d684
KB
189
190\membersection{wxString::Insert}\label{wxstringInsert}
191
f7bd2698 192\func{void}{Insert}{\param{const wxString\&}{ str}, \param{uint}{ index}}
a660d684 193
f7bd2698 194Add new element at the given position.
a660d684
KB
195
196\membersection{wxString::IsAscii}\label{wxstringIsAscii}
197
f7bd2698 198\constfunc{bool}{IsAscii}{\void}
a660d684 199
f7bd2698 200Returns TRUE if the string is ASCII.
a660d684 201
f7bd2698 202\membersection{wxString::IsEmpty}\label{wxstringisempty}
a660d684 203
f7bd2698 204\constfunc{bool}{IsEmpty}{\void}
a660d684 205
f7bd2698 206Returns TRUE if the string is NULL.
a660d684
KB
207
208\membersection{wxString::IsNull}\label{wxstringIsNull}
209
f7bd2698 210\constfunc{bool}{IsNull}{\void}
a660d684 211
f7bd2698 212Returns TRUE if the string is NULL (same as IsEmpty).
a660d684
KB
213
214\membersection{wxString::IsNumber}\label{wxstringIsNumber}
215
f7bd2698
JS
216\constfunc{bool}{IsNumber}{\void}
217
218Returns TRUE if the string is a number.
219
220\membersection{wxString::IsSameAs}\label{wxstringissameas}
221
222\constfunc{bool}{IsSameAs}{\param{const char*}{ psz}, \param{bool}{ caseSensitive = TRUE}}
223
224Test for string equality, case-sensitive (default) or not.
225
226caseSensitive is TRUE by default (case matters).
a660d684 227
f7bd2698
JS
228Returns TRUE if strings are equal, FALSE otherwise.
229
230See also Cmp, CmpNoCase.
a660d684
KB
231
232\membersection{wxString::IsWord}\label{wxstringIsWord}
233
f7bd2698 234\constfunc{bool}{IsWord}{\void}
a660d684 235
f7bd2698 236Returns TRUE if the string is a word. TODO: what's the definition of a word?
a660d684
KB
237
238\membersection{wxString::Last}\label{wxstringLast}
239
f7bd2698 240\constfunc{char}{Last}{\void}
a660d684 241
f7bd2698 242Returns the last character.
a660d684 243
f7bd2698 244\func{char\&}{Last}{\void}
a660d684 245
f7bd2698 246Returns a reference to the last character (writable).
a660d684 247
f7bd2698
JS
248\membersection{wxString::Left}\label{wxstringleft}
249
250\constfunc{wxString}{Left}{\param{size\_t}{ count}}
251
252Returns the first {\it count} characters.
253
254\constfunc{wxString}{Left}{\param{char}{ ch}}
255
256Returns all characters before the first occurence of {\it ch}.
257Returns the whole string if {\it ch} is not found.
a660d684 258
f7bd2698 259\membersection{wxString::Len}\label{wxstringlen}
a660d684 260
f7bd2698
JS
261\constfunc{size\_t}{Len}{\void}
262
263Returns the length of the string.
264
265\membersection{wxString::Length}\label{wxstringlength}
266
267\constfunc{size\_t}{Length}{\void}
268
269Returns the length of the string (same as Len).
a660d684
KB
270
271\membersection{wxString::LowerCase}\label{wxstringLowerCase}
272
f7bd2698
JS
273\func{void}{LowerCase}{\void}
274
275Same as MakeLower.
276
277\membersection{wxString::MakeLower}\label{wxstringmakelower}
278
279\func{void}{MakeLower}{\void}
280
281Converts all characters to lower case.
282
283\membersection{wxString::MakeUpper}\label{wxstringmakeupper}
284
285\func{void}{MakeUpper}{\void}
286
287Converts all characters to upper case.
a660d684
KB
288
289\membersection{wxString::Matches}\label{wxstringMatches}
290
f7bd2698
JS
291\constfunc{bool}{Matches}{\param{const char*}{ szMask}}
292
293Returns TRUE if the string contents matches a mask containing '*' and '?'.
a660d684 294
f7bd2698 295\membersection{wxString::Mid}\label{wxstringmid}
a660d684 296
f7bd2698 297\constfunc{wxString}{Mid}{\param{size\_t}{ first}, \param{size\_t}{ count = STRING\_MAXLEN}}
a660d684 298
f7bd2698
JS
299Returns a substring starting at {\it first}, with length {\it count}, or the rest of
300the string if {\it count} is the default value.
301
302\membersection{wxString::Pad}\label{wxstringpad}
303
304\func{wxString\&}{Pad}{\param{size\_t}{ count}, \param{char}{ pad = ' '}, \param{bool}{ fromRight = TRUE}}
305
306Adds {\it count} copies of {\it pad} to the beginning, or to the end of the string (the default).
307
308Removes spaces from the left or from the right (default).
a660d684
KB
309
310\membersection{wxString::Prepend}\label{wxstringPrepend}
311
f7bd2698 312\func{wxString\&}{Prepend}{\param{const wxString\&}{ str}}
a660d684 313
f7bd2698 314Prepends {\it str} to this string, returning a reference to this string.
a660d684 315
f7bd2698 316\membersection{wxString::Printf}\label{wxstringprintf}
a660d684 317
f7bd2698
JS
318\func{int}{Printf}{\param{const char* }{pszFormat}, \param{}{...}}
319
320Similar to sprintf. Returns the number of characters written, or an integer less than zero
321on error.
a660d684 322
f7bd2698
JS
323\membersection{wxString::PrintfV}\label{wxstringprintfv}
324
325\func{int}{PrintfV}{\param{const char* }{pszFormat}, \param{va\_list}{ argPtr}}
326
327Similar to vprintf. Returns the number of characters written, or an integer less than zero
328on error.
a660d684
KB
329
330\membersection{wxString::Remove}\label{wxstringRemove}
331
f7bd2698
JS
332\func{wxString\&}{Remove}{\param{size\_t}{ pos}}
333
334Same as Truncate. Removes the portion from {\it pos} to the end of the string.
335
336\func{wxString\&}{Remove}{\param{size\_t}{ pos}, \param{size\_t}{ len}}
337
338Removes the last {\it len} characters from the string, starting at {\it pos}.
339
340\membersection{wxString::RemoveLast}\label{wxstringremovelast}
a660d684 341
f7bd2698
JS
342\func{wxString\&}{RemoveLast}{\void}
343
344Removes the last character.
a660d684
KB
345
346\membersection{wxString::Replace}\label{wxstringReplace}
347
f7bd2698
JS
348\func{uint}{Replace}{\param{const char*}{ szOld}, \param{const char*}{ szNew}, \param{bool}{ replaceAll}}
349
350Replace first (or all) occurences of substring with another one.
351
352{\it replaceAll}: global replace (default), or only the first occurence.
353
354Returns the number of replacements made.
355
356\membersection{wxString::Right}\label{wxstringright}
357
358\constfunc{wxString}{Right}{\param{size\_t}{ count}}
a660d684 359
f7bd2698 360Returns the last {\it count} characters.
a660d684 361
f7bd2698 362\constfunc{wxString}{Right}{\param{char}{ ch}}
a660d684 363
f7bd2698
JS
364Returns all characters after the last occurence of {\it ch}.
365Returns the whole string if {\it ch} is not found.
a660d684 366
f7bd2698 367\membersection{wxString::SetChar}\label{wxstringsetchar}
a660d684 368
f7bd2698
JS
369\func{void}{SetChar}{\param{size\_t}{ n}, \param{char}{ch}}
370
371Sets the character at position {\it n}.
372
373\membersection{wxString::Shrink}\label{wxstringshrink}
374
375\func{void}{Shrink}{\void}
376
377Minimizes the string's memory. Only works if the data of this string is not shared.
a660d684
KB
378
379\membersection{wxString::sprintf}\label{wxstringsprintf}
a660d684 380
f7bd2698 381\func{void}{sprintf}{\param{const char* }{ fmt}}
a660d684 382
f7bd2698 383The same as Printf.
a660d684
KB
384
385\membersection{wxString::Strip}\label{wxstringStrip}
386
387\begin{verbatim}
f7bd2698 388enum stripType {leading = 0x1, trailing = 0x2, both = 0x3};
a660d684
KB
389\end{verbatim}
390
f7bd2698 391\constfunc{wxString}{Strip}{\param{stripType}{ s = trailing}}
a660d684 392
f7bd2698
JS
393Strip characters at the front and/or end. The same as Trim except that it
394doesn't change this string.
a660d684 395
f7bd2698 396\membersection{wxString::Trim}\label{wxstringtrim}
a660d684 397
f7bd2698 398\func{wxString\&}{Trim}{\param{bool}{ fromRight = TRUE}}
a660d684 399
f7bd2698 400Removes spaces from the left or from the right (default).
a660d684 401
f7bd2698 402\membersection{wxString::Truncate}\label{wxstringtruncate}
a660d684 403
f7bd2698 404\func{wxString\&}{Truncate}{\param{size\_t}{ len}}
a660d684 405
f7bd2698 406Truncate the string to the given length.
a660d684 407
f7bd2698
JS
408\membersection{wxString::UngetWriteBuf}\label{wxstringungetwritebuf}
409
410\func{void}{UngetWriteBuf}{\void}
411
412Puts the string back into a reasonable state, after
413\rtfsp\helpref{wxString::GetWriteBuf}{wxstringgetwritebuf} was called.
a660d684
KB
414
415\membersection{wxString::UpperCase}\label{wxstringUpperCase}
416
f7bd2698
JS
417\func{void}{UpperCase}{\void}
418
419The same as MakeUpper.
a660d684
KB
420
421\membersection{wxString::operator $=$}\label{wxstringoperatorassign}
422
f7bd2698
JS
423\func{wxString\&}{operator $=$}{\param{const wxString\&}{ str}}
424
425\func{wxString\&}{operator $=$}{\param{const char*}{ psz}}
426
427\func{wxString\&}{operator $=$}{\param{char}{ c}}
428
429\func{wxString\&}{operator $=$}{\param{const unsigned char*}{ psz}}
430
431\func{wxString\&}{operator $=$}{\param{const wchar\_t*}{ pwz}}
a660d684
KB
432
433Assignment.
5de76427
JS
434
435\membersection{operator wxString::$+$}\label{wxstringoperatorplus}
436
437Concatenation.
438
439\func{wxString}{operator $+$}{\param{const wxString\&}{ x}, \param{const wxString\&}{ y}}
440
441\func{wxString}{operator $+$}{\param{const wxString\&}{ x}, \param{const char*}{ y}}
442
443\func{wxString}{operator $+$}{\param{const wxString\&}{ x}, \param{char}{ y}}
444
445\func{wxString}{operator $+$}{\param{const char*}{ x}, \param{const wxString\&}{ y}}
446
a660d684
KB
447\membersection{wxString::operator $+=$}\label{wxstringPlusEqual}
448
f7bd2698
JS
449\func{void}{operator $+=$}{\param{const wxString\&}{ str}}
450
451\func{void}{operator $+=$}{\param{const char*}{ psz}}
452
453\func{void}{operator $+=$}{\param{char}{ c}}
a660d684
KB
454
455Concatenation.
456
457\membersection{wxString::operator []}\label{wxstringoperatorbracket}
458
f7bd2698
JS
459\func{char\&}{operator []}{\param{size\_t}{ i}}
460
461\func{char}{operator []}{\param{size\_t}{ i}}
462
463\func{char}{operator []}{\param{int}{ i}}
a660d684
KB
464
465Element extraction.
466
467\membersection{wxString::operator ()}\label{wxstringoperatorparenth}
468
f7bd2698
JS
469\func{wxString}{operator ()}{\param{size\_t}{ start}, \param{size\_t}{ len}}
470
471Same as Mid (substring extraction).
a660d684
KB
472
473\membersection{wxString::operator \cinsert}\label{wxstringoperatorout}
f7bd2698
JS
474
475\func{wxString\&}{operator \cinsert}{\\param{const wxString\&}{ str}}
476
477\func{wxString\&}{operator \cinsert}{\\param{const char*}{ psz}}
478
479\func{wxString\&}{operator \cinsert}{\\param{char }{ch}}
480
481Same as $+=$.
a660d684
KB
482
483\membersection{wxString::operator \cextract}\label{wxstringoperatorin}
a660d684 484
f7bd2698 485\func{friend istream\&}{operator \cextract}{\param{istream\&}{ is}, \param{wxString\&}{ str}}
a660d684 486
f7bd2698 487Extraction from a stream.
a660d684 488
f7bd2698 489\membersection{wxString::operator const char*}\label{wxstringoperatorconstcharpt}
a660d684 490
f7bd2698 491\constfunc{}{operator const char*}{\void}
a660d684 492
f7bd2698 493Implicit conversion to a C string.
a660d684 494
f7bd2698 495\membersection{Comparison operators}\label{wxstringComparison}
a660d684 496
f7bd2698 497\func{bool}{operator $==$}{\param{const wxString\&}{ x}, \param{const wxString\&}{ y}}
a660d684 498
f7bd2698 499\func{bool}{operator $==$}{\param{const wxString\&}{ x}, \param{const char*}{ t}}
a660d684 500
f7bd2698 501\func{bool}{operator $!=$}{\param{const wxString\&}{ x}, \param{const wxString\&}{ y}}
a660d684 502
f7bd2698 503\func{bool}{operator $!=$}{\param{const wxString\&}{ x}, \param{const char*}{ t}}
a660d684 504
f7bd2698 505\func{bool}{operator $>$}{\param{const wxString\&}{ x}, \param{const wxString\&}{ y}}
a660d684 506
f7bd2698 507\func{bool}{operator $>$}{\param{const wxString\&}{ x}, \param{const char*}{ t}}
a660d684 508
f7bd2698 509\func{bool}{operator $>=$}{\param{const wxString\&}{ x}, \param{const wxString\&}{ y}}
a660d684 510
f7bd2698 511\func{bool}{operator $>=$}{\param{const wxString\&}{ x}, \param{const char*}{ t}}
a660d684 512
f7bd2698 513\func{bool}{operator $<$}{\param{const wxString\&}{ x}, \param{const wxString\&}{ y}}
a660d684 514
f7bd2698 515\func{bool}{operator $<$}{\param{const wxString\&}{ x}, \param{const char*}{ t}}
a660d684 516
f7bd2698 517\func{bool}{operator $<=$}{\param{const wxString\&}{ x}, \param{const wxString\&}{ y}}
a660d684 518
f7bd2698 519\func{bool}{operator $<=$}{\param{const wxString\&}{ x}, \param{const char*}{ t}}
a660d684 520
f7bd2698 521\wxheading{Remarks}
a660d684 522
f7bd2698 523These comparisons are case-sensitive.
a660d684 524
a660d684 525