Documentation Center

  • Trials
  • Product Updates

strjoin

Join strings in cell array into single string

Syntax

Description

example

str = strjoin(C) constructs the string, str, by linking each string in the cell array, C, with a single space.

example

str = strjoin(C,delimiter) constructs the string, str, by linking each string of C with the elements in delimiter.

Examples

expand all

Join List of Words with Whitespace

Join individual strings in a cell array of strings, C, with a single space.

C = {'one','two','three'};
str = strjoin(C)
str =

one two three

Join Cell Array of Strings

C = {'Newton','Gauss','Euclid','Lagrange'};
str = strjoin(C,', ')
str =

Newton, Gauss, Euclid, Lagrange

Join Strings with Multiple Different Delimiters

Specify multiple different delimiters in a cell array of strings. The delimiter cell array must have one fewer element than C.

C = {'one','two','three'};
str = strjoin(C,{' + ',' = '})
str =

one + two = three

Input Arguments

expand all

C — Input text1-by-n cell array of strings

Input text, specified as a 1-by-n cell array of strings. Each element in the cell array must contain a single string in a single row.

Example: {'The','rain','in','Spain'}

Data Types: cell

delimiter — Delimiting charactersstring | 1-by-n cell array of strings

Delimiting characters, specified as a single string or a 1-by-n cell array of strings.

  • If delimiter is a single string, then strjoin forms str by inserting delimiter between each element of C. The delimiter input can include any of these escape sequences:

    \\

    Backslash

    \0

    Null

    \a

    Alarm

    \b

    Backspace

    \f

    Form feed

    \n

    New line

    \r

    Carriage return

    \t

    Horizontal tab

    \v

    Vertical tab

  • If delimiter is a cell array of strings, then it must contain one fewer element than C. Each element in the cell array must contain a single string in a single row. strjoin forms str by interleaving the elements of delimiter and C. All characters in delimiter are inserted as literal text, and escape sequences are not supported.

Example: ', '

Example: {',',' '}

Data Types: char | cell

See Also

| | |

Was this topic helpful?