Documentation

我们为许可用户提供了部分翻译好的中文文档。您只需登录便可查阅这些文档

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

collapse 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

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

    'Lincoln, Abraham'
    'Washington, George'

Input Arguments

collapse 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

collapse 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

| | | |

Introduced before R2006a

Was this topic helpful?