Next: , Previous:   [Contents][Index]


5 Strings

A string constant consists of a sequence of characters enclosed in either double-quote or single-quote marks. For example, both of the following expressions

"parrot"
'parrot'

represent the string whose contents are ‘parrot’. Strings in Octave can be of any length.

Since the single-quote mark is also used for the transpose operator (see Arithmetic Operators) but double-quote marks have no other purpose in Octave, it is best to use double-quote marks to denote strings.

Strings can be concatenated using the notation for defining matrices. For example, the expression

[ "foo" , "bar" , "baz" ]

produces the string whose contents are ‘foobarbaz’. See Numeric Data Types, for more information about creating matrices.

While strings can in principle store arbitrary content, most functions expect them to be UTF-8 encoded Unicode strings.

Furthermore, it is possible to create a string without actually writing a text. The function blanks creates a string of a given length consisting only of blank characters (ASCII code 32).

: blanks (n)

Return a string of n blanks.

For example:

blanks (10);
whos ans
     ⇒
      Attr Name        Size                     Bytes  Class
      ==== ====        ====                     =====  =====
           ans         1x10                        10  char

See also: repmat.