Mercurial > octave-nkf
annotate doc/interpreter/strings.txi @ 13943:5820f8ce683e
doc: Add undocumented functions to manual for 3.6.0 release
* gui.txi: New manual chapter for GUI-related functions
* Makefile.am: Add new gui.txi to build
* aspell-octave.en.pws: Add new words to spellcheck dictionary
* io.txi: Move file I/O dialogs to gui.txi
* octave.texi: Add new GUI chapter to manual
* strings.txi: Add is_dq_string and is_sq_string to manual
* system.txi: Add usejava to manual
* guidata.m: Fix incorrect use of @deftypefn
* uicontrol.m: Fix incorrect use of @deftypefn
* uiresume.m: Fix incorrect use of @deftypefn
* uiwait.m: Fix incorrect use of @deftypefn
* addpref.m, getpref.m, ispref.m, rmpref.m, setpref.m: Adjust seealso links
author | Rik <octave@nomad.inbox5.com> |
---|---|
date | Sat, 26 Nov 2011 17:25:05 -0800 |
parents | c8be316f9543 |
children | 72c96de7a403 |
rev | line source |
---|---|
11523 | 1 @c Copyright (C) 1996-2011 John W. Eaton |
7018 | 2 @c |
3 @c This file is part of Octave. | |
4 @c | |
5 @c Octave is free software; you can redistribute it and/or modify it | |
6 @c under the terms of the GNU General Public License as published by the | |
7 @c Free Software Foundation; either version 3 of the License, or (at | |
8 @c your option) any later version. | |
9 @c | |
10 @c Octave is distributed in the hope that it will be useful, but WITHOUT | |
11 @c ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
12 @c FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
13 @c for more details. | |
14 @c | |
15 @c You should have received a copy of the GNU General Public License | |
16 @c along with Octave; see the file COPYING. If not, see | |
17 @c <http://www.gnu.org/licenses/>. | |
3294 | 18 |
4167 | 19 @node Strings |
3294 | 20 @chapter Strings |
21 @cindex strings | |
22 @cindex character strings | |
23 @opindex " | |
24 @opindex ' | |
25 | |
26 A @dfn{string constant} consists of a sequence of characters enclosed in | |
27 either double-quote or single-quote marks. For example, both of the | |
28 following expressions | |
29 | |
30 @example | |
31 @group | |
32 "parrot" | |
33 'parrot' | |
34 @end group | |
35 @end example | |
36 | |
37 @noindent | |
38 represent the string whose contents are @samp{parrot}. Strings in | |
39 Octave can be of any length. | |
40 | |
41 Since the single-quote mark is also used for the transpose operator | |
8351
4d78baf20ded
improve string documentation
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8347
diff
changeset
|
42 (@pxref{Arithmetic Ops}) but double-quote marks have no other purpose in Octave, |
4d78baf20ded
improve string documentation
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8347
diff
changeset
|
43 it is best to use double-quote marks to denote strings. |
4d78baf20ded
improve string documentation
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8347
diff
changeset
|
44 |
4d78baf20ded
improve string documentation
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8347
diff
changeset
|
45 Strings can be concatenated using the notation for defining matrices. For |
4d78baf20ded
improve string documentation
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8347
diff
changeset
|
46 example, the expression |
4d78baf20ded
improve string documentation
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8347
diff
changeset
|
47 |
4d78baf20ded
improve string documentation
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8347
diff
changeset
|
48 @example |
4d78baf20ded
improve string documentation
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8347
diff
changeset
|
49 [ "foo" , "bar" , "baz" ] |
4d78baf20ded
improve string documentation
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8347
diff
changeset
|
50 @end example |
3294 | 51 |
8351
4d78baf20ded
improve string documentation
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8347
diff
changeset
|
52 @noindent |
4d78baf20ded
improve string documentation
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8347
diff
changeset
|
53 produces the string whose contents are @samp{foobarbaz}. @xref{Numeric Data |
4d78baf20ded
improve string documentation
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8347
diff
changeset
|
54 Types}, for more information about creating matrices. |
4d78baf20ded
improve string documentation
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8347
diff
changeset
|
55 |
4d78baf20ded
improve string documentation
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8347
diff
changeset
|
56 @menu |
11255
d682cd6669ac
Update info-based documentation menus to include new nodes.
Rik <octave@nomad.inbox5.com>
parents:
11143
diff
changeset
|
57 * Escape Sequences in String Constants:: |
8351
4d78baf20ded
improve string documentation
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8347
diff
changeset
|
58 * Character Arrays:: |
4d78baf20ded
improve string documentation
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8347
diff
changeset
|
59 * Creating Strings:: |
4d78baf20ded
improve string documentation
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8347
diff
changeset
|
60 * Comparing Strings:: |
4d78baf20ded
improve string documentation
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8347
diff
changeset
|
61 * Manipulating Strings:: |
4d78baf20ded
improve string documentation
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8347
diff
changeset
|
62 * String Conversions:: |
4d78baf20ded
improve string documentation
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8347
diff
changeset
|
63 * Character Class Functions:: |
4d78baf20ded
improve string documentation
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8347
diff
changeset
|
64 @end menu |
4d78baf20ded
improve string documentation
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8347
diff
changeset
|
65 |
11257
8d4c57258523
fix some menu problems in the manual
John W. Eaton <jwe@octave.org>
parents:
11255
diff
changeset
|
66 @node Escape Sequences in String Constants |
8d4c57258523
fix some menu problems in the manual
John W. Eaton <jwe@octave.org>
parents:
11255
diff
changeset
|
67 @section Escape Sequences in String Constants |
6554 | 68 @cindex escape sequence notation |
69 In double-quoted strings, the backslash character is used to introduce | |
6623 | 70 @dfn{escape sequences} that represent other characters. For example, |
6554 | 71 @samp{\n} embeds a newline character in a double-quoted string and |
8351
4d78baf20ded
improve string documentation
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8347
diff
changeset
|
72 @samp{\"} embeds a double quote character. In single-quoted strings, backslash |
4d78baf20ded
improve string documentation
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8347
diff
changeset
|
73 is not a special character. Here is an example showing the difference: |
3294 | 74 |
6554 | 75 @example |
6556 | 76 @group |
6554 | 77 toascii ("\n") |
6570 | 78 @result{} 10 |
6554 | 79 toascii ('\n') |
6570 | 80 @result{} [ 92 110 ] |
6556 | 81 @end group |
6554 | 82 @end example |
3294 | 83 |
8351
4d78baf20ded
improve string documentation
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8347
diff
changeset
|
84 Here is a table of all the escape sequences used in Octave (within |
4d78baf20ded
improve string documentation
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8347
diff
changeset
|
85 double quoted strings). They are the same as those used in the C |
4d78baf20ded
improve string documentation
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8347
diff
changeset
|
86 programming language. |
3294 | 87 |
88 @table @code | |
89 @item \\ | |
90 Represents a literal backslash, @samp{\}. | |
91 | |
92 @item \" | |
93 Represents a literal double-quote character, @samp{"}. | |
94 | |
95 @item \' | |
96 Represents a literal single-quote character, @samp{'}. | |
97 | |
3893 | 98 @item \0 |
4946 | 99 Represents the ``nul'' character, control-@@, ASCII code 0. |
3893 | 100 |
3294 | 101 @item \a |
102 Represents the ``alert'' character, control-g, ASCII code 7. | |
103 | |
104 @item \b | |
105 Represents a backspace, control-h, ASCII code 8. | |
106 | |
107 @item \f | |
108 Represents a formfeed, control-l, ASCII code 12. | |
109 | |
110 @item \n | |
111 Represents a newline, control-j, ASCII code 10. | |
112 | |
113 @item \r | |
114 Represents a carriage return, control-m, ASCII code 13. | |
115 | |
116 @item \t | |
117 Represents a horizontal tab, control-i, ASCII code 9. | |
118 | |
119 @item \v | |
120 Represents a vertical tab, control-k, ASCII code 11. | |
121 | |
122 @c We don't do octal or hex this way yet. | |
123 @c | |
124 @c @item \@var{nnn} | |
125 @c Represents the octal value @var{nnn}, where @var{nnn} are one to three | |
126 @c digits between 0 and 7. For example, the code for the ASCII ESC | |
127 @c (escape) character is @samp{\033}.@refill | |
128 @c | |
129 @c @item \x@var{hh}@dots{} | |
130 @c Represents the hexadecimal value @var{hh}, where @var{hh} are hexadecimal | |
131 @c digits (@samp{0} through @samp{9} and either @samp{A} through @samp{F} or | |
132 @c @samp{a} through @samp{f}). Like the same construct in @sc{ansi} C, | |
133 @c the escape | |
134 @c sequence continues until the first non-hexadecimal digit is seen. However, | |
135 @c using more than two hexadecimal digits produces undefined results. (The | |
136 @c @samp{\x} escape sequence is not allowed in @sc{posix} @code{awk}.)@refill | |
137 @end table | |
138 | |
8351
4d78baf20ded
improve string documentation
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8347
diff
changeset
|
139 In a single-quoted string there is only one escape sequence: you may insert a |
4d78baf20ded
improve string documentation
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8347
diff
changeset
|
140 single quote character using two single quote characters in succession. For |
4d78baf20ded
improve string documentation
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8347
diff
changeset
|
141 example, |
3294 | 142 |
143 @example | |
8351
4d78baf20ded
improve string documentation
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8347
diff
changeset
|
144 @group |
4d78baf20ded
improve string documentation
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8347
diff
changeset
|
145 'I can''t escape' |
4d78baf20ded
improve string documentation
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8347
diff
changeset
|
146 @result{} I can't escape |
4d78baf20ded
improve string documentation
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8347
diff
changeset
|
147 @end group |
3294 | 148 @end example |
149 | |
13943
5820f8ce683e
doc: Add undocumented functions to manual for 3.6.0 release
Rik <octave@nomad.inbox5.com>
parents:
12581
diff
changeset
|
150 In scripts the two different string types can be distinguished if necessary |
5820f8ce683e
doc: Add undocumented functions to manual for 3.6.0 release
Rik <octave@nomad.inbox5.com>
parents:
12581
diff
changeset
|
151 by using @code{is_dq_string} and @code{is_sq_string}. |
5820f8ce683e
doc: Add undocumented functions to manual for 3.6.0 release
Rik <octave@nomad.inbox5.com>
parents:
12581
diff
changeset
|
152 |
5820f8ce683e
doc: Add undocumented functions to manual for 3.6.0 release
Rik <octave@nomad.inbox5.com>
parents:
12581
diff
changeset
|
153 @DOCSTRING(is_dq_string) |
5820f8ce683e
doc: Add undocumented functions to manual for 3.6.0 release
Rik <octave@nomad.inbox5.com>
parents:
12581
diff
changeset
|
154 |
5820f8ce683e
doc: Add undocumented functions to manual for 3.6.0 release
Rik <octave@nomad.inbox5.com>
parents:
12581
diff
changeset
|
155 @DOCSTRING(is_sq_string) |
3294 | 156 |
8351
4d78baf20ded
improve string documentation
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8347
diff
changeset
|
157 @node Character Arrays |
4d78baf20ded
improve string documentation
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8347
diff
changeset
|
158 @section Character Arrays |
3294 | 159 |
6623 | 160 The string representation used by Octave is an array of characters, so |
8351
4d78baf20ded
improve string documentation
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8347
diff
changeset
|
161 internally the string "dddddddddd" is actually a row vector of length 10 |
4d78baf20ded
improve string documentation
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8347
diff
changeset
|
162 containing the value 100 in all places (100 is the ASCII code of "d"). This |
9209
923c7cb7f13f
Simplify TeXinfo files by eliminating redundant @iftex followed by @tex construction.
Rik <rdrider0-list@yahoo.com>
parents:
9036
diff
changeset
|
163 lends itself to the obvious generalization to character matrices. Using a |
8351
4d78baf20ded
improve string documentation
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8347
diff
changeset
|
164 matrix of characters, it is possible to represent a collection of same-length |
4d78baf20ded
improve string documentation
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8347
diff
changeset
|
165 strings in one variable. The convention used in Octave is that each row in a |
4d78baf20ded
improve string documentation
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8347
diff
changeset
|
166 character matrix is a separate string, but letting each column represent a |
4d78baf20ded
improve string documentation
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8347
diff
changeset
|
167 string is equally possible. |
6623 | 168 |
169 The easiest way to create a character matrix is to put several strings | |
170 together into a matrix. | |
171 | |
172 @example | |
173 collection = [ "String #1"; "String #2" ]; | |
174 @end example | |
175 | |
176 @noindent | |
177 This creates a 2-by-9 character matrix. | |
178 | |
8351
4d78baf20ded
improve string documentation
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8347
diff
changeset
|
179 The function @code{ischar} can be used to test if an object is a character |
4d78baf20ded
improve string documentation
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8347
diff
changeset
|
180 matrix. |
4d78baf20ded
improve string documentation
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8347
diff
changeset
|
181 |
4d78baf20ded
improve string documentation
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8347
diff
changeset
|
182 @DOCSTRING(ischar) |
4d78baf20ded
improve string documentation
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8347
diff
changeset
|
183 |
4d78baf20ded
improve string documentation
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8347
diff
changeset
|
184 To test if an object is a string (i.e., a character vector and not a character |
4d78baf20ded
improve string documentation
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8347
diff
changeset
|
185 matrix) you can use the @code{ischar} function in combination with the |
4d78baf20ded
improve string documentation
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8347
diff
changeset
|
186 @code{isvector} function as in the following example: |
4d78baf20ded
improve string documentation
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8347
diff
changeset
|
187 |
4d78baf20ded
improve string documentation
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8347
diff
changeset
|
188 @example |
4d78baf20ded
improve string documentation
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8347
diff
changeset
|
189 @group |
4d78baf20ded
improve string documentation
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8347
diff
changeset
|
190 ischar(collection) |
4d78baf20ded
improve string documentation
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8347
diff
changeset
|
191 @result{} ans = 1 |
8442
502e58a0d44f
Fix docstrings, add examples, references and tests to string functions
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8372
diff
changeset
|
192 |
8351
4d78baf20ded
improve string documentation
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8347
diff
changeset
|
193 ischar(collection) && isvector(collection) |
4d78baf20ded
improve string documentation
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8347
diff
changeset
|
194 @result{} ans = 0 |
8442
502e58a0d44f
Fix docstrings, add examples, references and tests to string functions
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8372
diff
changeset
|
195 |
8351
4d78baf20ded
improve string documentation
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8347
diff
changeset
|
196 ischar("my string") && isvector("my string") |
4d78baf20ded
improve string documentation
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8347
diff
changeset
|
197 @result{} ans = 1 |
4d78baf20ded
improve string documentation
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8347
diff
changeset
|
198 @end group |
4d78baf20ded
improve string documentation
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8347
diff
changeset
|
199 @end example |
4d78baf20ded
improve string documentation
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8347
diff
changeset
|
200 |
4d78baf20ded
improve string documentation
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8347
diff
changeset
|
201 One relevant question is, what happens when a character matrix is |
4d78baf20ded
improve string documentation
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8347
diff
changeset
|
202 created from strings of different length. The answer is that Octave |
6623 | 203 puts blank characters at the end of strings shorter than the longest |
8351
4d78baf20ded
improve string documentation
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8347
diff
changeset
|
204 string. It is possible to use a different character than the |
4d78baf20ded
improve string documentation
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8347
diff
changeset
|
205 blank character using the @code{string_fill_char} function. |
4d78baf20ded
improve string documentation
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8347
diff
changeset
|
206 |
4d78baf20ded
improve string documentation
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8347
diff
changeset
|
207 @DOCSTRING(string_fill_char) |
4d78baf20ded
improve string documentation
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8347
diff
changeset
|
208 |
4d78baf20ded
improve string documentation
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8347
diff
changeset
|
209 This shows a problem with character matrices. It simply isn't possible to |
4d78baf20ded
improve string documentation
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8347
diff
changeset
|
210 represent strings of different lengths. The solution is to use a cell array of |
4d78baf20ded
improve string documentation
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8347
diff
changeset
|
211 strings, which is described in @ref{Cell Arrays of Strings}. |
4d78baf20ded
improve string documentation
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8347
diff
changeset
|
212 |
4d78baf20ded
improve string documentation
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8347
diff
changeset
|
213 @node Creating Strings |
4d78baf20ded
improve string documentation
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8347
diff
changeset
|
214 @section Creating Strings |
4d78baf20ded
improve string documentation
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8347
diff
changeset
|
215 |
4d78baf20ded
improve string documentation
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8347
diff
changeset
|
216 The easiest way to create a string is, as illustrated in the introduction, |
4d78baf20ded
improve string documentation
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8347
diff
changeset
|
217 to enclose a text in double-quotes or single-quotes. It is however |
4d78baf20ded
improve string documentation
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8347
diff
changeset
|
218 possible to create a string without actually writing a text. The |
4d78baf20ded
improve string documentation
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8347
diff
changeset
|
219 function @code{blanks} creates a string of a given length consisting |
4d78baf20ded
improve string documentation
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8347
diff
changeset
|
220 only of blank characters (ASCII code 32). |
4d78baf20ded
improve string documentation
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8347
diff
changeset
|
221 |
4d78baf20ded
improve string documentation
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8347
diff
changeset
|
222 @DOCSTRING(blanks) |
4d78baf20ded
improve string documentation
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8347
diff
changeset
|
223 |
4d78baf20ded
improve string documentation
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8347
diff
changeset
|
224 @menu |
4d78baf20ded
improve string documentation
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8347
diff
changeset
|
225 * Concatenating Strings:: |
4d78baf20ded
improve string documentation
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8347
diff
changeset
|
226 * Conversion of Numerical Data to Strings:: |
4d78baf20ded
improve string documentation
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8347
diff
changeset
|
227 @end menu |
4d78baf20ded
improve string documentation
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8347
diff
changeset
|
228 |
4d78baf20ded
improve string documentation
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8347
diff
changeset
|
229 @node Concatenating Strings |
4d78baf20ded
improve string documentation
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8347
diff
changeset
|
230 @subsection Concatenating Strings |
4d78baf20ded
improve string documentation
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8347
diff
changeset
|
231 |
4d78baf20ded
improve string documentation
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8347
diff
changeset
|
232 It has been shown above that strings can be concatenated using matrix notation |
4d78baf20ded
improve string documentation
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8347
diff
changeset
|
233 (@pxref{Strings}, @ref{Character Arrays}). Apart from that, there are several |
8372
8dff9cba15fe
move str2mat to deprecated and make it a simple wrapper around char
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8351
diff
changeset
|
234 functions to concatenate string objects: @code{char}, |
8351
4d78baf20ded
improve string documentation
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8347
diff
changeset
|
235 @code{strvcat}, @code{strcat} and @code{cstrcat}. In addition, the general |
4d78baf20ded
improve string documentation
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8347
diff
changeset
|
236 purpose concatenation functions can be used: see @ref{doc-cat,,cat}, |
4d78baf20ded
improve string documentation
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8347
diff
changeset
|
237 @ref{doc-horzcat,,horzcat} and @ref{doc-vertcat,,vertcat}. |
4d78baf20ded
improve string documentation
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8347
diff
changeset
|
238 |
4d78baf20ded
improve string documentation
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8347
diff
changeset
|
239 @itemize @bullet |
4d78baf20ded
improve string documentation
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8347
diff
changeset
|
240 @item All string concatenation functions except @code{cstrcat} |
4d78baf20ded
improve string documentation
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8347
diff
changeset
|
241 convert numerical input into character data by taking the corresponding ASCII |
4d78baf20ded
improve string documentation
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8347
diff
changeset
|
242 character for each element, as in the following example: |
4d78baf20ded
improve string documentation
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8347
diff
changeset
|
243 |
4d78baf20ded
improve string documentation
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8347
diff
changeset
|
244 @example |
4d78baf20ded
improve string documentation
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8347
diff
changeset
|
245 @group |
4d78baf20ded
improve string documentation
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8347
diff
changeset
|
246 char([98, 97, 110, 97, 110, 97]) |
4d78baf20ded
improve string documentation
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8347
diff
changeset
|
247 @result{} ans = |
4d78baf20ded
improve string documentation
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8347
diff
changeset
|
248 banana |
4d78baf20ded
improve string documentation
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8347
diff
changeset
|
249 @end group |
4d78baf20ded
improve string documentation
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8347
diff
changeset
|
250 @end example |
4d78baf20ded
improve string documentation
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8347
diff
changeset
|
251 |
4d78baf20ded
improve string documentation
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8347
diff
changeset
|
252 @item |
8372
8dff9cba15fe
move str2mat to deprecated and make it a simple wrapper around char
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8351
diff
changeset
|
253 @code{char} and @code{strvcat} |
8351
4d78baf20ded
improve string documentation
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8347
diff
changeset
|
254 concatenate vertically, while @code{strcat} and @code{cstrcat} concatenate |
4d78baf20ded
improve string documentation
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8347
diff
changeset
|
255 horizontally. For example: |
4d78baf20ded
improve string documentation
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8347
diff
changeset
|
256 |
4d78baf20ded
improve string documentation
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8347
diff
changeset
|
257 @example |
4d78baf20ded
improve string documentation
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8347
diff
changeset
|
258 @group |
4d78baf20ded
improve string documentation
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8347
diff
changeset
|
259 char("an apple", "two pears") |
4d78baf20ded
improve string documentation
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8347
diff
changeset
|
260 @result{} ans = |
4d78baf20ded
improve string documentation
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8347
diff
changeset
|
261 an apple |
4d78baf20ded
improve string documentation
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8347
diff
changeset
|
262 two pears |
4d78baf20ded
improve string documentation
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8347
diff
changeset
|
263 @end group |
4d78baf20ded
improve string documentation
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8347
diff
changeset
|
264 |
4d78baf20ded
improve string documentation
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8347
diff
changeset
|
265 @group |
4d78baf20ded
improve string documentation
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8347
diff
changeset
|
266 strcat("oc", "tave", " is", " good", " for you") |
4d78baf20ded
improve string documentation
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8347
diff
changeset
|
267 @result{} ans = |
4d78baf20ded
improve string documentation
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8347
diff
changeset
|
268 octave is good for you |
4d78baf20ded
improve string documentation
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8347
diff
changeset
|
269 @end group |
4d78baf20ded
improve string documentation
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8347
diff
changeset
|
270 @end example |
4d78baf20ded
improve string documentation
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8347
diff
changeset
|
271 |
8372
8dff9cba15fe
move str2mat to deprecated and make it a simple wrapper around char
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8351
diff
changeset
|
272 @item @code{char} generates an empty row in the output |
8351
4d78baf20ded
improve string documentation
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8347
diff
changeset
|
273 for each empty string in the input. @code{strvcat}, on the other hand, |
4d78baf20ded
improve string documentation
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8347
diff
changeset
|
274 eliminates empty strings. |
4d78baf20ded
improve string documentation
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8347
diff
changeset
|
275 |
4d78baf20ded
improve string documentation
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8347
diff
changeset
|
276 @example |
4d78baf20ded
improve string documentation
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8347
diff
changeset
|
277 @group |
4d78baf20ded
improve string documentation
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8347
diff
changeset
|
278 char("orange", "green", "", "red") |
4d78baf20ded
improve string documentation
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8347
diff
changeset
|
279 @result{} ans = |
4d78baf20ded
improve string documentation
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8347
diff
changeset
|
280 orange |
4d78baf20ded
improve string documentation
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8347
diff
changeset
|
281 green |
4d78baf20ded
improve string documentation
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8347
diff
changeset
|
282 |
4d78baf20ded
improve string documentation
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8347
diff
changeset
|
283 red |
4d78baf20ded
improve string documentation
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8347
diff
changeset
|
284 @end group |
4d78baf20ded
improve string documentation
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8347
diff
changeset
|
285 |
4d78baf20ded
improve string documentation
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8347
diff
changeset
|
286 @group |
4d78baf20ded
improve string documentation
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8347
diff
changeset
|
287 strvcat("orange", "green", "", "red") |
4d78baf20ded
improve string documentation
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8347
diff
changeset
|
288 @result{} ans = |
4d78baf20ded
improve string documentation
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8347
diff
changeset
|
289 orange |
4d78baf20ded
improve string documentation
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8347
diff
changeset
|
290 green |
4d78baf20ded
improve string documentation
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8347
diff
changeset
|
291 red |
4d78baf20ded
improve string documentation
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8347
diff
changeset
|
292 @end group |
4d78baf20ded
improve string documentation
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8347
diff
changeset
|
293 @end example |
4d78baf20ded
improve string documentation
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8347
diff
changeset
|
294 |
4d78baf20ded
improve string documentation
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8347
diff
changeset
|
295 @item All string concatenation functions except @code{cstrcat} also accept cell |
8372
8dff9cba15fe
move str2mat to deprecated and make it a simple wrapper around char
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8351
diff
changeset
|
296 array data (@pxref{Cell Arrays}). @code{char} and |
8351
4d78baf20ded
improve string documentation
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8347
diff
changeset
|
297 @code{strvcat} convert cell arrays into character arrays, while @code{strcat} |
4d78baf20ded
improve string documentation
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8347
diff
changeset
|
298 concatenates within the cells of the cell arrays: |
4d78baf20ded
improve string documentation
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8347
diff
changeset
|
299 |
4d78baf20ded
improve string documentation
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8347
diff
changeset
|
300 @example |
4d78baf20ded
improve string documentation
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8347
diff
changeset
|
301 @group |
4d78baf20ded
improve string documentation
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8347
diff
changeset
|
302 char(@{"red", "green", "", "blue"@}) |
4d78baf20ded
improve string documentation
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8347
diff
changeset
|
303 @result{} ans = |
4d78baf20ded
improve string documentation
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8347
diff
changeset
|
304 red |
4d78baf20ded
improve string documentation
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8347
diff
changeset
|
305 green |
4d78baf20ded
improve string documentation
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8347
diff
changeset
|
306 |
4d78baf20ded
improve string documentation
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8347
diff
changeset
|
307 blue |
4d78baf20ded
improve string documentation
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8347
diff
changeset
|
308 @end group |
4d78baf20ded
improve string documentation
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8347
diff
changeset
|
309 |
4d78baf20ded
improve string documentation
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8347
diff
changeset
|
310 @group |
4d78baf20ded
improve string documentation
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8347
diff
changeset
|
311 strcat(@{"abc"; "ghi"@}, @{"def"; "jkl"@}) |
4d78baf20ded
improve string documentation
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8347
diff
changeset
|
312 @result{} ans = |
4d78baf20ded
improve string documentation
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8347
diff
changeset
|
313 @{ |
4d78baf20ded
improve string documentation
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8347
diff
changeset
|
314 [1,1] = abcdef |
4d78baf20ded
improve string documentation
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8347
diff
changeset
|
315 [2,1] = ghijkl |
4d78baf20ded
improve string documentation
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8347
diff
changeset
|
316 @} |
4d78baf20ded
improve string documentation
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8347
diff
changeset
|
317 @end group |
4d78baf20ded
improve string documentation
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8347
diff
changeset
|
318 @end example |
4d78baf20ded
improve string documentation
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8347
diff
changeset
|
319 |
4d78baf20ded
improve string documentation
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8347
diff
changeset
|
320 @item @code{strcat} removes trailing white space in the arguments (except |
4d78baf20ded
improve string documentation
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8347
diff
changeset
|
321 within cell arrays), while @code{cstrcat} leaves white space untouched. Both |
9036
58604c45ca74
Cleanup of data types related documentation
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
322 kinds of behavior can be useful as can be seen in the examples: |
8351
4d78baf20ded
improve string documentation
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8347
diff
changeset
|
323 |
4d78baf20ded
improve string documentation
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8347
diff
changeset
|
324 @example |
4d78baf20ded
improve string documentation
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8347
diff
changeset
|
325 @group |
4d78baf20ded
improve string documentation
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8347
diff
changeset
|
326 strcat(["dir1";"directory2"], ["/";"/"], ["file1";"file2"]) |
4d78baf20ded
improve string documentation
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8347
diff
changeset
|
327 @result{} ans = |
4d78baf20ded
improve string documentation
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8347
diff
changeset
|
328 dir1/file1 |
4d78baf20ded
improve string documentation
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8347
diff
changeset
|
329 directory2/file2 |
4d78baf20ded
improve string documentation
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8347
diff
changeset
|
330 @end group |
4d78baf20ded
improve string documentation
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8347
diff
changeset
|
331 @group |
4d78baf20ded
improve string documentation
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8347
diff
changeset
|
332 |
4d78baf20ded
improve string documentation
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8347
diff
changeset
|
333 cstrcat(["thirteen apples"; "a banana"], [" 5$";" 1$"]) |
4d78baf20ded
improve string documentation
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8347
diff
changeset
|
334 @result{} ans = |
4d78baf20ded
improve string documentation
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8347
diff
changeset
|
335 thirteen apples 5$ |
4d78baf20ded
improve string documentation
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8347
diff
changeset
|
336 a banana 1$ |
4d78baf20ded
improve string documentation
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8347
diff
changeset
|
337 @end group |
4d78baf20ded
improve string documentation
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8347
diff
changeset
|
338 @end example |
4d78baf20ded
improve string documentation
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8347
diff
changeset
|
339 |
4d78baf20ded
improve string documentation
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8347
diff
changeset
|
340 Note that in the above example for @code{cstrcat}, the white space originates |
4d78baf20ded
improve string documentation
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8347
diff
changeset
|
341 from the internal representation of the strings in a string array |
4d78baf20ded
improve string documentation
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8347
diff
changeset
|
342 (@pxref{Character Arrays}). |
4d78baf20ded
improve string documentation
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8347
diff
changeset
|
343 @end itemize |
6623 | 344 |
4358 | 345 @DOCSTRING(char) |
346 | |
6502 | 347 @DOCSTRING(strvcat) |
348 | |
8351
4d78baf20ded
improve string documentation
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8347
diff
changeset
|
349 @DOCSTRING(strcat) |
4d78baf20ded
improve string documentation
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8347
diff
changeset
|
350 |
8286
6f2d95255911
fix @seealso references to point to existing anchors
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
7984
diff
changeset
|
351 @DOCSTRING(cstrcat) |
6f2d95255911
fix @seealso references to point to existing anchors
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
7984
diff
changeset
|
352 |
8351
4d78baf20ded
improve string documentation
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8347
diff
changeset
|
353 @node Conversion of Numerical Data to Strings |
4d78baf20ded
improve string documentation
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8347
diff
changeset
|
354 @subsection Conversion of Numerical Data to Strings |
4d78baf20ded
improve string documentation
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8347
diff
changeset
|
355 Apart from the string concatenation functions (@pxref{Concatenating Strings}) |
4d78baf20ded
improve string documentation
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8347
diff
changeset
|
356 which cast numerical data to the corresponding ASCII characters, there are |
4d78baf20ded
improve string documentation
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8347
diff
changeset
|
357 several functions that format numerical data as strings. @code{mat2str} and |
4d78baf20ded
improve string documentation
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8347
diff
changeset
|
358 @code{num2str} convert real or complex matrices, while @code{int2str} converts |
4d78baf20ded
improve string documentation
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8347
diff
changeset
|
359 integer matrices. @code{int2str} takes the real part of complex values and |
4d78baf20ded
improve string documentation
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8347
diff
changeset
|
360 round fractional values to integer. A more flexible way to format numerical |
4d78baf20ded
improve string documentation
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8347
diff
changeset
|
361 data as strings is the @code{sprintf} function (@pxref{Formatted Output}, |
4d78baf20ded
improve string documentation
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8347
diff
changeset
|
362 @ref{doc-sprintf}). |
4535 | 363 |
6502 | 364 @DOCSTRING(mat2str) |
365 | |
366 @DOCSTRING(num2str) | |
3294 | 367 |
6623 | 368 @DOCSTRING(int2str) |
369 | |
370 @node Comparing Strings | |
371 @section Comparing Strings | |
372 | |
8828 | 373 Since a string is a character array, comparisons between strings work |
374 element by element as the following example shows: | |
6623 | 375 |
376 @example | |
9209
923c7cb7f13f
Simplify TeXinfo files by eliminating redundant @iftex followed by @tex construction.
Rik <rdrider0-list@yahoo.com>
parents:
9036
diff
changeset
|
377 @group |
6623 | 378 GNU = "GNU's Not UNIX"; |
379 spaces = (GNU == " ") | |
8351
4d78baf20ded
improve string documentation
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8347
diff
changeset
|
380 @result{} spaces = |
4d78baf20ded
improve string documentation
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8347
diff
changeset
|
381 0 0 0 0 0 1 0 0 0 1 0 0 0 0 |
9209
923c7cb7f13f
Simplify TeXinfo files by eliminating redundant @iftex followed by @tex construction.
Rik <rdrider0-list@yahoo.com>
parents:
9036
diff
changeset
|
382 @end group |
6623 | 383 @end example |
384 | |
8351
4d78baf20ded
improve string documentation
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8347
diff
changeset
|
385 @noindent To determine if two strings are identical it is necessary to use the |
4d78baf20ded
improve string documentation
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8347
diff
changeset
|
386 @code{strcmp} function. It compares complete strings and is case |
9036
58604c45ca74
Cleanup of data types related documentation
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
387 sensitive. @code{strncmp} compares only the first @code{N} characters (with |
8351
4d78baf20ded
improve string documentation
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8347
diff
changeset
|
388 @code{N} given as a parameter). @code{strcmpi} and @code{strncmpi} are the |
4d78baf20ded
improve string documentation
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8347
diff
changeset
|
389 corresponding functions for case-insensitive comparison. |
6623 | 390 |
391 @DOCSTRING(strcmp) | |
392 | |
8351
4d78baf20ded
improve string documentation
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8347
diff
changeset
|
393 @DOCSTRING(strncmp) |
6623 | 394 |
8351
4d78baf20ded
improve string documentation
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8347
diff
changeset
|
395 @DOCSTRING(strcmpi) |
6623 | 396 |
397 @DOCSTRING(strncmpi) | |
398 | |
8351
4d78baf20ded
improve string documentation
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8347
diff
changeset
|
399 @DOCSTRING(validatestring) |
7984
bbaa5d7d0143
Some documentation updates
David Bateman <dbateman@free.fr>
parents:
7639
diff
changeset
|
400 |
6623 | 401 @node Manipulating Strings |
402 @section Manipulating Strings | |
403 | |
404 Octave supports a wide range of functions for manipulating strings. | |
405 Since a string is just a matrix, simple manipulations can be accomplished | |
9036
58604c45ca74
Cleanup of data types related documentation
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
406 using standard operators. The following example shows how to replace |
6623 | 407 all blank characters with underscores. |
408 | |
409 @example | |
9036
58604c45ca74
Cleanup of data types related documentation
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
410 @group |
9209
923c7cb7f13f
Simplify TeXinfo files by eliminating redundant @iftex followed by @tex construction.
Rik <rdrider0-list@yahoo.com>
parents:
9036
diff
changeset
|
411 quote = ... |
7081 | 412 "First things first, but not necessarily in that order"; |
6623 | 413 quote( quote == " " ) = "_" |
7081 | 414 @result{} quote = |
415 First_things_first,_but_not_necessarily_in_that_order | |
9036
58604c45ca74
Cleanup of data types related documentation
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
416 @end group |
6623 | 417 @end example |
418 | |
419 For more complex manipulations, such as searching, replacing, and | |
7001 | 420 general regular expressions, the following functions come with Octave. |
3294 | 421 |
3361 | 422 @DOCSTRING(deblank) |
3294 | 423 |
8817
03b7f618ab3d
include docstrings for new functions in the manual
John W. Eaton <jwe@octave.org>
parents:
8442
diff
changeset
|
424 @DOCSTRING(strtrim) |
03b7f618ab3d
include docstrings for new functions in the manual
John W. Eaton <jwe@octave.org>
parents:
8442
diff
changeset
|
425 |
8351
4d78baf20ded
improve string documentation
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8347
diff
changeset
|
426 @DOCSTRING(strtrunc) |
4d78baf20ded
improve string documentation
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8347
diff
changeset
|
427 |
3361 | 428 @DOCSTRING(findstr) |
3294 | 429 |
8817
03b7f618ab3d
include docstrings for new functions in the manual
John W. Eaton <jwe@octave.org>
parents:
8442
diff
changeset
|
430 @DOCSTRING(strchr) |
03b7f618ab3d
include docstrings for new functions in the manual
John W. Eaton <jwe@octave.org>
parents:
8442
diff
changeset
|
431 |
3361 | 432 @DOCSTRING(index) |
3294 | 433 |
3361 | 434 @DOCSTRING(rindex) |
3294 | 435 |
6502 | 436 @DOCSTRING(strfind) |
437 | |
438 @DOCSTRING(strmatch) | |
439 | |
440 @DOCSTRING(strtok) | |
441 | |
8879
1beaaffb3c1f
document strsplit, not split
John W. Eaton <jwe@octave.org>
parents:
8828
diff
changeset
|
442 @DOCSTRING(strsplit) |
3294 | 443 |
11143
195cffc2d0a3
strings.txi: @DOCSTRING additions.
Ben Abbott <bpabbott@mac.com>
parents:
11103
diff
changeset
|
444 @DOCSTRING(strread) |
195cffc2d0a3
strings.txi: @DOCSTRING additions.
Ben Abbott <bpabbott@mac.com>
parents:
11103
diff
changeset
|
445 |
3361 | 446 @DOCSTRING(strrep) |
3294 | 447 |
3361 | 448 @DOCSTRING(substr) |
3294 | 449 |
5582 | 450 @DOCSTRING(regexp) |
451 | |
452 @DOCSTRING(regexpi) | |
453 | |
6549 | 454 @DOCSTRING(regexprep) |
455 | |
7984
bbaa5d7d0143
Some documentation updates
David Bateman <dbateman@free.fr>
parents:
7639
diff
changeset
|
456 @DOCSTRING(regexptranslate) |
bbaa5d7d0143
Some documentation updates
David Bateman <dbateman@free.fr>
parents:
7639
diff
changeset
|
457 |
11103
d4fc294a19e4
include untabify docstring in the manual
John W. Eaton <jwe@octave.org>
parents:
10828
diff
changeset
|
458 @DOCSTRING(untabify) |
d4fc294a19e4
include untabify docstring in the manual
John W. Eaton <jwe@octave.org>
parents:
10828
diff
changeset
|
459 |
4167 | 460 @node String Conversions |
3294 | 461 @section String Conversions |
462 | |
6623 | 463 Octave supports various kinds of conversions between strings and |
8351
4d78baf20ded
improve string documentation
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8347
diff
changeset
|
464 numbers. As an example, it is possible to convert a string containing |
6623 | 465 a hexadecimal number to a floating point number. |
466 | |
467 @example | |
9209
923c7cb7f13f
Simplify TeXinfo files by eliminating redundant @iftex followed by @tex construction.
Rik <rdrider0-list@yahoo.com>
parents:
9036
diff
changeset
|
468 @group |
6623 | 469 hex2dec ("FF") |
470 @result{} ans = 255 | |
9209
923c7cb7f13f
Simplify TeXinfo files by eliminating redundant @iftex followed by @tex construction.
Rik <rdrider0-list@yahoo.com>
parents:
9036
diff
changeset
|
471 @end group |
6623 | 472 @end example |
473 | |
3361 | 474 @DOCSTRING(bin2dec) |
3294 | 475 |
3361 | 476 @DOCSTRING(dec2bin) |
3294 | 477 |
3361 | 478 @DOCSTRING(dec2hex) |
3294 | 479 |
3361 | 480 @DOCSTRING(hex2dec) |
3294 | 481 |
3920 | 482 @DOCSTRING(dec2base) |
483 | |
484 @DOCSTRING(base2dec) | |
485 | |
7639
b2fbb393a072
Add the num2hex and hex2num functions
David Bateman <dbateman@free.fr>
parents:
7081
diff
changeset
|
486 @DOCSTRING(num2hex) |
b2fbb393a072
Add the num2hex and hex2num functions
David Bateman <dbateman@free.fr>
parents:
7081
diff
changeset
|
487 |
b2fbb393a072
Add the num2hex and hex2num functions
David Bateman <dbateman@free.fr>
parents:
7081
diff
changeset
|
488 @DOCSTRING(hex2num) |
b2fbb393a072
Add the num2hex and hex2num functions
David Bateman <dbateman@free.fr>
parents:
7081
diff
changeset
|
489 |
6623 | 490 @DOCSTRING(str2double) |
3920 | 491 |
6623 | 492 @DOCSTRING(strjust) |
6502 | 493 |
3361 | 494 @DOCSTRING(str2num) |
3294 | 495 |
3361 | 496 @DOCSTRING(toascii) |
3294 | 497 |
3361 | 498 @DOCSTRING(tolower) |
3294 | 499 |
3361 | 500 @DOCSTRING(toupper) |
3294 | 501 |
3428 | 502 @DOCSTRING(do_string_escapes) |
503 | |
3361 | 504 @DOCSTRING(undo_string_escapes) |
3294 | 505 |
4167 | 506 @node Character Class Functions |
3294 | 507 @section Character Class Functions |
508 | |
509 Octave also provides the following character class test functions | |
510 patterned after the functions in the standard C library. They all | |
511 operate on string arrays and return matrices of zeros and ones. | |
512 Elements that are nonzero indicate that the condition was true for the | |
10828
322f43e0e170
Grammarcheck .txi documentation files.
Rik <octave@nomad.inbox5.com>
parents:
9209
diff
changeset
|
513 corresponding character in the string array. For example: |
3294 | 514 |
515 @example | |
516 @group | |
517 isalpha ("!Q@@WERT^Y&") | |
518 @result{} [ 0, 1, 0, 1, 1, 1, 1, 0, 1, 0 ] | |
519 @end group | |
520 @end example | |
521 | |
3361 | 522 @DOCSTRING(isalnum) |
3294 | 523 |
3361 | 524 @DOCSTRING(isalpha) |
525 | |
6549 | 526 @DOCSTRING(isletter) |
527 | |
3361 | 528 @DOCSTRING(islower) |
3294 | 529 |
12581
c8be316f9543
Group commonly used isXXX functions together in documentation.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
530 @DOCSTRING(isupper) |
c8be316f9543
Group commonly used isXXX functions together in documentation.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
531 |
c8be316f9543
Group commonly used isXXX functions together in documentation.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
532 @DOCSTRING(isdigit) |
c8be316f9543
Group commonly used isXXX functions together in documentation.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
533 |
c8be316f9543
Group commonly used isXXX functions together in documentation.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
534 @DOCSTRING(isxdigit) |
3294 | 535 |
3361 | 536 @DOCSTRING(ispunct) |
3294 | 537 |
3361 | 538 @DOCSTRING(isspace) |
3294 | 539 |
12581
c8be316f9543
Group commonly used isXXX functions together in documentation.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
540 @DOCSTRING(iscntrl) |
c8be316f9543
Group commonly used isXXX functions together in documentation.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
541 |
c8be316f9543
Group commonly used isXXX functions together in documentation.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
542 @DOCSTRING(isgraph) |
3294 | 543 |
12581
c8be316f9543
Group commonly used isXXX functions together in documentation.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
544 @DOCSTRING(isprint) |
c8be316f9543
Group commonly used isXXX functions together in documentation.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
545 |
c8be316f9543
Group commonly used isXXX functions together in documentation.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
546 @DOCSTRING(isascii) |
7984
bbaa5d7d0143
Some documentation updates
David Bateman <dbateman@free.fr>
parents:
7639
diff
changeset
|
547 |
bbaa5d7d0143
Some documentation updates
David Bateman <dbateman@free.fr>
parents:
7639
diff
changeset
|
548 @DOCSTRING(isstrprop) |