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