Documentation

This is machine translation

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

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

strcat

Concatenate strings horizontally

Syntax

s = strcat(s1,...,sN)

Description

example

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

  • If any input is a string array, then the result is a string array.

  • If any input is a cell array, and none are string arrays, then the result is a cell array of character vectors.

  • If all inputs are character arrays, then 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 and string array inputs, strcat does not remove trailing white space.

Examples

collapse all

s1 = 'Good';
s2 = 'morning';
s = strcat(s1,s2)
s = 
'Goodmorning'
s1 = {'abcde','fghi'};
s2 = {'jkl','mn'};
s = strcat(s1,s2)
s = 1x2 cell array
    {'abcdejkl'}    {'fghimn'}

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

Starting in R2017a, you can create string arrays using double quotes instead of the string function. Concatenate them with the strcat function.

str1 = ["John ","Mary "];
str2 = ["Smith","Jones"];
str = strcat(str1,str2)
str = 1x2 string array
    "John Smith"    "Mary Jones"

Concatenate a character vector onto each element of the string array.

str = strcat(str,', M.D.')
str = 1x2 string array
    "John Smith, M.D."    "Mary Jones, M.D."

Text processing functions (such as strfind and regexp) accept string arrays as inputs, but other functions (for example, addpath) do not.

Input Arguments

collapse all

Input text, specified as character arrays, cell arrays of character vectors, or string arrays. When combining string or cell arrays with character arrays, the string or cell arrays must be either scalars or column vectors with the same number of rows as the character arrays.

Data Types: char | cell | string

Tips

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

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

Introduced before R2006a