strcat

Concatenate strings horizontally

Syntax

Description

example

s = strcat(s1,...,sN) horizontally concatenates strings s1,...,sN. Each input argument can be a single string, a collection of strings in a cell array, or a collection of strings in a character array.

If any input argument is a cell array, the result is a cell array of strings. Otherwise, the result is a character array.

For character array inputs, strcat removes trailing ASCII white-space characters: space, tab, vertical tab, newline, carriage return, and form feed. For cell array inputs, strcat does not remove trailing white space.

Examples

expand all

Concatenate Two Strings

s1 = 'Good';
s2 = 'morning';
s = strcat(s1,s2)
s =

Goodmorning

Concatenate Two Cell Arrays

s1 = {'abcde','fghi'};
s2 = {'jkl','mn'};
s = strcat(s1,s2)
s = 

    'abcdejkl'    'fghimn'

Concatenate Two Cell Arrays with Scalar Cell Array

s1 = {'abcde','fghi'};
s2 = {'jkl','mn'};
s3 =  {'Q'};
s = strcat(s1,s2,s3)
s = 

    'abcdejklQ'    'fghimnQ'

Input Arguments

expand all

s1,...,sN — Input stringscharacter arrays | cell array of strings

Input strings, specified as cell arrays of strings or character arrays with the same number of rows. When combining nonscalar cell arrays and multirow character arrays, cell arrays must be column vectors with the same number of rows as the character arrays.

Data Types: char | cell

More About

expand all

Tips

  • Strings also can be concatenated using left and right square brackets.

    s1 = 'Good ';
    s2 = 'Morning';
    s = [s1 s2]
    
    s =
    
    Good Morning

See Also

| | | |

Was this topic helpful?