strcat
Concatenate strings horizontally
Syntax
Description
Note
append
is recommended over strcat
because
it provides greater flexibility and allows vectorization. For additional
information, see Alternative Functionality.
s = strcat(
horizontally
concatenates the text in its input arguments. Each input argument can be a character
array, a cell array of character vectors, or a string array.s1,...,sN
)
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
whitespace characters: space, tab, vertical tab, newline, carriage return, and form
feed. For cell array and string array inputs, strcat
does not
remove trailing white space.
For faster performance and to preserve trailing whitespace characters, use append
.
Examples
Input Arguments
Alternative Functionality
Update existing code that makes use of strcat
to use append
or
syntaxes specific to character vectors and strings. Note that append
does not remove trailing whitespace characters. Character arrays also can be
concatenated using left and right square brackets. String arrays can be concatenated
using the +
operator. For example:
Not Recommended | Recommended | Square Brackets | + Operator |
---|---|---|---|
char1 = 'Good '; char2 = 'Morning'; char3 = strcat(char1,char2) char3 = 'GoodMorning' |
char1 = 'Good '; char2 = 'Morning'; char3 = append(char1,char2) char3 = 'Good Morning' |
char1 = 'Good '; char2 = 'Morning'; char3 = [char1 char2] char3 = 'Good Morning' |
str1 = "Good "; str2 = "Morning"; str3 = str1 + str2 str3 = "Good Morning" |
Extended Capabilities
Version History
Introduced before R2006a