Next: , Up: Strings


5.1 Creating Strings

— Function File: blanks (n)

Return a string of n blanks.

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

Create a string array from a numeric matrix, cell array, or list of

If the argument is a numeric matrix, each element of the matrix is converted to the corresponding ASCII character. For example,

          char ([97, 98, 99])
               => "abc"
     

If the argument is a cell array of strings, the result is a string array with each element corresponding to one element of the cell array.

For multiple string arguments, the result is a string array with each element corresponding to the arguments.

The returned values are padded with blanks as needed to make each row of the string array have the same length.

— Function File: int2str (n)
— Function File: num2str (x, precision)
— Function File: num2str (x, format)

Convert a number to a string. These functions are not very flexible, but are provided for compatibility with Matlab. For better control over the results, use sprintf (see Formatted Output).

     
     
See also: sprintf, num2str.

— Function File: com2str (zz, flg)

This function has been deprecated. Use num2str instead.

Convert complex number to a string. Inputs

zz
complex number
flg
format flag 0 (default): -1, 0, 1, 1i, 1 + 0.5i 1 (for use with zpout): -1, 0, + 1, + 1i, + 1 + 0.5i

— Function File: strcat (s1, s2, ...)

Return a string containing all the arguments concatenated. For example,

          s = [ "ab"; "cde" ];
          strcat (s, s, s)
          => "ab ab ab "
                  "cdecdecde"
     

— Built-in Variable: string_fill_char

The value of this variable is used to pad all strings in a string matrix to the same length. It should be a single character. The default value is " " (a single space). For example,

          string_fill_char = "X";
          [ "these"; "are"; "strings" ]
               => "theseXX"
                  "areXXXX"
                  "strings"
     

— Function File: str2mat (s_1, ..., s_n)

Return a matrix containing the strings s_1, ..., s_n as its rows. Each string is padded with blanks in order to form a valid matrix.

This function is modelled after Matlab. In Octave, you can create a matrix of strings by [s_1; ...; s_n] even if the strings are not all the same length.

— Built-in Function: ischar (a)

Return 1 if a is a string. Otherwise, return 0.

— Function File: isstr (a)

This function has been deprecated. Use ischar instead.