Documentation

strjoin

Join text in array

Syntax

str = strjoin(C)
str = strjoin(C,delimiter)

Description

example

str = strjoin(C)constructs a single piece of text,str,by linking each element in the array,C,with a single space.Ccan be a cell array of character vectors or a string array.

example

str = strjoin(Cdelimiter)constructsstrby linking each element ofCwith the elements indelimiter.

Examples

collapse all

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

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

Join the character vectors in a cell array into one character vector. Specify a comma followed by a space character as the delimiter.

C = {'Newton''Gauss''Euclid''Lagrange'}
C =1x4 cell array{'Newton'} {'Gauss'} {'Euclid'} {'Lagrange'}
str = strjoin(C,', ')
str = 'Newton, Gauss, Euclid, Lagrange'

Specify multiple different delimiters in a cell array of character vectors. Thedelimitercell array must have one fewer element thanC.

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

Input Arguments

collapse all

Input text, specified as a1-by-N单元阵列特征向量数组或字符串。

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

Example:string({'Four','score','and','seven'})

Data Types:cell|string

Delimiting characters, specified as a character vector, a1-by-Ncell array of character vectors, or a1-by-Nstring array.

  • Ifdelimiteris a character vector, thenstrjoinformsstrby insertingdelimiterbetween each element ofC. Thedelimiter在put 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

  • Ifdelimiteris a cell array of character vectors, then it must contain one fewer element thanC. Each element in the cell array must contain a character vector.strjoinformsstrby interleaving the elements ofdelimiterandC. All characters indelimiterare inserted as literal text, and escape sequences are not supported.

Example:', '

Example:{',',' '}

Data Types:char|cell|string

Tips

  • Starting in R2016b, thejoinfunction is recommended to join elements of a string array.

Extended Capabilities

Introduced in R2013a

Was this topic helpful?