manpagez: man pages & more
info octave
Home | html | info | man
[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

5.3.1 Concatenating Strings

It has been shown above that strings can be concatenated using matrix notation (see section Strings, Character Arrays). Apart from that, there are several functions to concatenate string objects: char, strvcat, strcat and cstrcat. In addition, the general purpose concatenation functions can be used: see cat, horzcat and vertcat.

Built-in Function: char (x)
Built-in Function: char (x, …)
Built-in Function: char (s1, s2, …)
Built-in Function: char (cell_array)

Create a string array from one or more numeric matrices, character matrices, or cell arrays. 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.

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).

For cell arrays, each element is concatenated separately. Cell arrays converted through char can mostly be converted back with cellstr. For example,

 
char ([97, 98, 99], "", {"98", "99", 100}, "str1", ["ha", "lf"])
     ⇒ ["abc    "
         "       "
         "98     "
         "99     "
         "d      "
         "str1   "
         "half   "]

See also: strvcat, cellstr.

Built-in Function: strvcat (x)
Built-in Function: strvcat (x, …)
Built-in Function: strvcat (s1, s2, …)
Built-in Function: strvcat (cell_array)

Create a character array from one or more numeric matrices, character matrices, or cell arrays. 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 char, empty strings are removed and will not appear in the output.

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).

For cell arrays, each element is concatenated separately. Cell arrays converted through strvcat can mostly be converted back with cellstr. For example,

 
strvcat ([97, 98, 99], "", {"98", "99", 100}, "str1", ["ha", "lf"])
     ⇒ ["abc    "
         "98     "
         "99     "
         "d      "
         "str1   "
         "half   "]

See also: char, strcat, cstrcat.

Function File: strcat (s1, s2, …)

Return a string containing all the arguments concatenated horizontally. If the arguments are cells strings, strcat returns a cell string with the individual cells concatenated. For numerical input, each element is converted to the corresponding ASCII character. Trailing white space is eliminated. For example,

 
s = [ "ab"; "cde" ];
strcat (s, s, s)
     ⇒ ans =
        "ab ab ab "
        "cdecdecde"
 
s = { "ab"; "cde" };
strcat (s, s, s)
     ⇒ ans =
        {
          [1,1] = ababab
          [2,1] = cdecdecde
        }

See also: cstrcat, char, strvcat.

Function File: cstrcat (s1, s2, …)

Return a string containing all the arguments concatenated horizontally. Trailing white space is preserved. For example,

 
cstrcat ("ab   ", "cd")
     ⇒ "ab   cd"
 
s = [ "ab"; "cde" ];
cstrcat (s, s, s)
     ⇒ ans =
        "ab ab ab "
        "cdecdecde"

See also: strcat, char, strvcat.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]
© manpagez.com 2000-2024
Individual documents may contain additional copyright information.