Documentation

This is machine translation

Translated by Microsoft
Mouse over text to see original. Click the button below to return to the English verison of the page.

strcat

Concatenate strings horizontally

Syntax

Description

example

s = strcat(s1,...,sN) horizontally concatenates character arrays s1,...,sN. Each input argument can be a character array or a cell array of character vectors.

If any input argument is a cell array, the result is a cell array of character vectors. 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

collapse all

Concatenate Two Character Vectors

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

firstnames = {'Abraham'; 'George'};
lastnames = {'Lincoln'; 'Washington'};
names = strcat(lastnames, {', '}, firstnames)
names = 

    'Lincoln, Abraham'
    'Washington, George'

Input Arguments

collapse all

s1,...,sN — Input textcharacter arrays | cell array of vectors

Input text, specified as character arrays or cell arrays of character vectors. 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

collapse all

Tips

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

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

See Also

| | | |

Introduced before R2006a

Was this topic helpful?