strjoin - Join strings in array - MATLAB (original) (raw)

Syntax

Description

Note

join is recommended overstrjoin because it provides greater flexibility and allows vectorization. For more information, see Alternative Functionality.

str = strjoin([C](#btnav7t-C)) constructsstr by linking the elements of C with a space between consecutive elements. C can be a cell array of character vectors or a string array.

example

str = strjoin([C](#btnav7t-C),[delimiter](#btnav7t-delimiter)) constructs str by linking each element of C with the elements in delimiter.

example

Examples

collapse all

Join List of Words with Whitespace

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

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

Join Cell Array of Character Vectors with Delimiter

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 {'Newton'} {'Gauss'} {'Euclid'} {'Lagrange'}

str = 'Newton, Gauss, Euclid, Lagrange'

Join Character Vectors with Multiple Different Delimiters

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

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

str = 'one + two = three'

Input Arguments

collapse all

C — Input text

1-by-n cell array of character vectors | 1-by-n string array

Input text, specified as a 1-by-n cell array of character vectors or string array.

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

Example: ["Four","score","and","seven"]

Data Types: cell | string

delimiter — Delimiting characters

character vector | 1-by-n cell array of character vectors | 1-by-n string array

Delimiting characters, specified as a character vector, a1-by-n cell array of character vectors, or a 1-by-n string array.

Example: ', '

Example: {',',' '}

Data Types: char | cell | string

Alternative Functionality

Update code that makes use of strjoin to use join instead. strjoin returns a character vector if the input is a cell array of character vectors and returns a string scalar if the input is a string array. join returns a text scalar of the same type as the input. For example:

Not Recommended Direct Replacement Match Original Behavior
C = {'one','two','three'}; str = strjoin(C) str = 'one two three' C = {'one','two','three'}; str = join(C) str = {'one two three'} C = {'one','two','three'}; str = char(join(C)) str = 'one two three'

Extended Capabilities

C/C++ Code Generation

Generate C and C++ code using MATLAB® Coder™.

Usage notes and limitations:

Thread-Based Environment

Run code in the background using MATLAB® backgroundPool or accelerate code with Parallel Computing Toolbox™ ThreadPool.

This function fully supports thread-based environments. For more information, see Run MATLAB Functions in Thread-Based Environment.

Version History

Introduced in R2013a