/usr/share/doc/octave/octave.html/Concatenating-Strings.html is in octave-doc 4.2.2-1ubuntu1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 | <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<!-- Created by GNU Texinfo 6.5, http://www.gnu.org/software/texinfo/ -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Concatenating Strings (GNU Octave)</title>
<meta name="description" content="Concatenating Strings (GNU Octave)">
<meta name="keywords" content="Concatenating Strings (GNU Octave)">
<meta name="resource-type" content="document">
<meta name="distribution" content="global">
<meta name="Generator" content="makeinfo">
<link href="index.html#Top" rel="start" title="Top">
<link href="Concept-Index.html#Concept-Index" rel="index" title="Concept Index">
<link href="index.html#SEC_Contents" rel="contents" title="Table of Contents">
<link href="Creating-Strings.html#Creating-Strings" rel="up" title="Creating Strings">
<link href="Converting-Numerical-Data-to-Strings.html#Converting-Numerical-Data-to-Strings" rel="next" title="Converting Numerical Data to Strings">
<link href="Creating-Strings.html#Creating-Strings" rel="prev" title="Creating Strings">
<style type="text/css">
<!--
a.summary-letter {text-decoration: none}
blockquote.indentedblock {margin-right: 0em}
blockquote.smallindentedblock {margin-right: 0em; font-size: smaller}
blockquote.smallquotation {font-size: smaller}
div.display {margin-left: 3.2em}
div.example {margin-left: 3.2em}
div.lisp {margin-left: 3.2em}
div.smalldisplay {margin-left: 3.2em}
div.smallexample {margin-left: 3.2em}
div.smalllisp {margin-left: 3.2em}
kbd {font-style: oblique}
pre.display {font-family: inherit}
pre.format {font-family: inherit}
pre.menu-comment {font-family: serif}
pre.menu-preformatted {font-family: serif}
pre.smalldisplay {font-family: inherit; font-size: smaller}
pre.smallexample {font-size: smaller}
pre.smallformat {font-family: inherit; font-size: smaller}
pre.smalllisp {font-size: smaller}
span.nolinebreak {white-space: nowrap}
span.roman {font-family: initial; font-weight: normal}
span.sansserif {font-family: sans-serif; font-weight: normal}
ul.no-bullet {list-style: none}
-->
</style>
<link rel="stylesheet" type="text/css" href="octave.css">
</head>
<body lang="en">
<a name="Concatenating-Strings"></a>
<div class="header">
<p>
Next: <a href="Converting-Numerical-Data-to-Strings.html#Converting-Numerical-Data-to-Strings" accesskey="n" rel="next">Converting Numerical Data to Strings</a>, Up: <a href="Creating-Strings.html#Creating-Strings" accesskey="u" rel="up">Creating Strings</a> [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Concept-Index.html#Concept-Index" title="Index" rel="index">Index</a>]</p>
</div>
<hr>
<a name="Concatenating-Strings-1"></a>
<h4 class="subsection">5.3.1 Concatenating Strings</h4>
<p>Strings can be concatenated using matrix notation
(see <a href="Strings.html#Strings">Strings</a>, <a href="Character-Arrays.html#Character-Arrays">Character Arrays</a>) which is often the most natural
method. For example:
</p>
<div class="example">
<pre class="example">fullname = [fname ".txt"];
email = ["<" user "@" domain ">"];
</pre></div>
<p>In each case it is easy to see what the final string will look like. This
method is also the most efficient. When using matrix concatenation the parser
immediately begins joining the strings without having to process
the overhead of a function call and the input validation of the associated
function.
</p>
<p>Nevertheless, there are several other functions for concatenating string
objects which can be useful in specific circumstances: <code>char</code>,
<code>strvcat</code>, <code>strcat</code>, and <code>cstrcat</code>. Finally, the general
purpose concatenation functions can be used: see <a href="Rearranging-Matrices.html#XREFcat">cat</a>,
<a href="Rearranging-Matrices.html#XREFhorzcat">horzcat</a>, and <a href="Rearranging-Matrices.html#XREFvertcat">vertcat</a>.
</p>
<ul>
<li> All string concatenation functions except <code>cstrcat</code>
convert numerical input into character data by taking the corresponding ASCII
character for each element, as in the following example:
<div class="example">
<pre class="example">char ([98, 97, 110, 97, 110, 97])
⇒ banana
</pre></div>
</li><li> <code>char</code> and <code>strvcat</code>
concatenate vertically, while <code>strcat</code> and <code>cstrcat</code> concatenate
horizontally. For example:
<div class="example">
<pre class="example">char ("an apple", "two pears")
⇒ an apple
two pears
</pre><pre class="example">
</pre><pre class="example">strcat ("oc", "tave", " is", " good", " for you")
⇒ octave is good for you
</pre></div>
</li><li> <code>char</code> generates an empty row in the output
for each empty string in the input. <code>strvcat</code>, on the other hand,
eliminates empty strings.
<div class="example">
<pre class="example">char ("orange", "green", "", "red")
⇒ orange
green
red
</pre><pre class="example">
</pre><pre class="example">strvcat ("orange", "green", "", "red")
⇒ orange
green
red
</pre></div>
</li><li> All string concatenation functions except <code>cstrcat</code> also accept cell
array data (see <a href="Cell-Arrays.html#Cell-Arrays">Cell Arrays</a>). <code>char</code> and
<code>strvcat</code> convert cell arrays into character arrays, while <code>strcat</code>
concatenates within the cells of the cell arrays:
<div class="example">
<pre class="example">char ({"red", "green", "", "blue"})
⇒ red
green
blue
</pre><pre class="example">
</pre><pre class="example">strcat ({"abc"; "ghi"}, {"def"; "jkl"})
⇒
{
[1,1] = abcdef
[2,1] = ghijkl
}
</pre></div>
</li><li> <code>strcat</code> removes trailing white space in the arguments (except
within cell arrays), while <code>cstrcat</code> leaves white space untouched. Both
kinds of behavior can be useful as can be seen in the examples:
<div class="example">
<pre class="example">strcat (["dir1";"directory2"], ["/";"/"], ["file1";"file2"])
⇒ dir1/file1
directory2/file2
</pre><pre class="example">
cstrcat (["thirteen apples"; "a banana"], [" 5$";" 1$"])
⇒ thirteen apples 5$
a banana 1$
</pre></div>
<p>Note that in the above example for <code>cstrcat</code>, the white space originates
from the internal representation of the strings in a string array
(see <a href="Character-Arrays.html#Character-Arrays">Character Arrays</a>).
</p></li></ul>
<a name="XREFchar"></a><dl>
<dt><a name="index-char"></a>: <em></em> <strong>char</strong> <em>(<var>x</var>)</em></dt>
<dt><a name="index-char-1"></a>: <em></em> <strong>char</strong> <em>(<var>x</var>, …)</em></dt>
<dt><a name="index-char-2"></a>: <em></em> <strong>char</strong> <em>(<var>s1</var>, <var>s2</var>, …)</em></dt>
<dt><a name="index-char-3"></a>: <em></em> <strong>char</strong> <em>(<var>cell_array</var>)</em></dt>
<dd><p>Create a string array from one or more numeric matrices, character
matrices, or cell arrays.
</p>
<p>Arguments are concatenated vertically. The returned values are padded with
blanks as needed to make each row of the string array have the same length.
Empty input strings are significant and will concatenated in the output.
</p>
<p>For numerical input, each element is converted to the corresponding ASCII
character. A range error results if an input is outside the ASCII range
(0-255).
</p>
<p>For cell arrays, each element is concatenated separately. Cell arrays
converted through <code>char</code> can mostly be converted back with
<code>cellstr</code>. For example:
</p>
<div class="example">
<pre class="example">char ([97, 98, 99], "", {"98", "99", 100}, "str1", ["ha", "lf"])
⇒ ["abc "
" "
"98 "
"99 "
"d "
"str1"
"half"]
</pre></div>
<p><strong>See also:</strong> <a href="#XREFstrvcat">strvcat</a>, <a href="Cell-Arrays-of-Strings.html#XREFcellstr">cellstr</a>.
</p></dd></dl>
<a name="XREFstrvcat"></a><dl>
<dt><a name="index-strvcat"></a>: <em></em> <strong>strvcat</strong> <em>(<var>x</var>)</em></dt>
<dt><a name="index-strvcat-1"></a>: <em></em> <strong>strvcat</strong> <em>(<var>x</var>, …)</em></dt>
<dt><a name="index-strvcat-2"></a>: <em></em> <strong>strvcat</strong> <em>(<var>s1</var>, <var>s2</var>, …)</em></dt>
<dt><a name="index-strvcat-3"></a>: <em></em> <strong>strvcat</strong> <em>(<var>cell_array</var>)</em></dt>
<dd><p>Create a character array from one or more numeric matrices, character
matrices, or cell arrays.
</p>
<p>Arguments are concatenated vertically. The returned values are padded with
blanks as needed to make each row of the string array have the same length.
Unlike <code>char</code>, empty strings are removed and will not appear in the
output.
</p>
<p>For numerical input, each element is converted to the corresponding ASCII
character. A range error results if an input is outside the ASCII range
(0-255).
</p>
<p>For cell arrays, each element is concatenated separately. Cell arrays
converted through <code>strvcat</code> can mostly be converted back with
<code>cellstr</code>. For example:
</p>
<div class="example">
<pre class="example">strvcat ([97, 98, 99], "", {"98", "99", 100}, "str1", ["ha", "lf"])
⇒ ["abc "
"98 "
"99 "
"d "
"str1"
"half"]
</pre></div>
<p><strong>See also:</strong> <a href="#XREFchar">char</a>, <a href="#XREFstrcat">strcat</a>, <a href="#XREFcstrcat">cstrcat</a>.
</p></dd></dl>
<a name="XREFstrcat"></a><dl>
<dt><a name="index-strcat"></a>: <em></em> <strong>strcat</strong> <em>(<var>s1</var>, <var>s2</var>, …)</em></dt>
<dd><p>Return a string containing all the arguments concatenated
horizontally.
</p>
<p>If the arguments are cell strings, <code>strcat</code> returns a cell string
with the individual cells concatenated. For numerical input, each element
is converted to the corresponding ASCII character. Trailing white space
for any character string input is eliminated before the strings are
concatenated. Note that cell string values do <strong>not</strong> have
whitespace trimmed.
</p>
<p>For example:
</p>
<div class="example">
<pre class="example">strcat ("|", " leading space is preserved", "|")
⇒ | leading space is preserved|
</pre></div>
<div class="example">
<pre class="example">strcat ("|", "trailing space is eliminated ", "|")
⇒ |trailing space is eliminated|
</pre></div>
<div class="example">
<pre class="example">strcat ("homogeneous space |", " ", "| is also eliminated")
⇒ homogeneous space || is also eliminated
</pre></div>
<div class="example">
<pre class="example">s = [ "ab"; "cde" ];
strcat (s, s, s)
⇒
"ababab "
"cdecdecde"
</pre></div>
<div class="example">
<pre class="example">s = { "ab"; "cd " };
strcat (s, s, s)
⇒
{
[1,1] = ababab
[2,1] = cd cd cd
}
</pre></div>
<p><strong>See also:</strong> <a href="#XREFcstrcat">cstrcat</a>, <a href="#XREFchar">char</a>, <a href="#XREFstrvcat">strvcat</a>.
</p></dd></dl>
<a name="XREFcstrcat"></a><dl>
<dt><a name="index-cstrcat"></a>: <em></em> <strong>cstrcat</strong> <em>(<var>s1</var>, <var>s2</var>, …)</em></dt>
<dd><p>Return a string containing all the arguments concatenated horizontally
with trailing white space preserved.
</p>
<p>For example:
</p>
<div class="example">
<pre class="example">cstrcat ("ab ", "cd")
⇒ "ab cd"
</pre></div>
<div class="example">
<pre class="example">s = [ "ab"; "cde" ];
cstrcat (s, s, s)
⇒ "ab ab ab "
"cdecdecde"
</pre></div>
<p><strong>See also:</strong> <a href="#XREFstrcat">strcat</a>, <a href="#XREFchar">char</a>, <a href="#XREFstrvcat">strvcat</a>.
</p></dd></dl>
<hr>
<div class="header">
<p>
Next: <a href="Converting-Numerical-Data-to-Strings.html#Converting-Numerical-Data-to-Strings" accesskey="n" rel="next">Converting Numerical Data to Strings</a>, Up: <a href="Creating-Strings.html#Creating-Strings" accesskey="u" rel="up">Creating Strings</a> [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Concept-Index.html#Concept-Index" title="Index" rel="index">Index</a>]</p>
</div>
</body>
</html>
|