strjoin
Join strings in array
Description
Examples
Join List of Words with Whitespace
Join individual character vectors in a cell array of character vectors, C
, with a single space.
C = {'one','two','three'}; str = strjoin(C)
str = 'one two three'
Join Cell Array of Character Vectors with Delimiter
Join the character vectors in a cell array into one character vector. Specify a comma followed by a space character as the delimiter.
C = {'Newton','Gauss','Euclid','Lagrange'}
C = 1x4 cell
{'Newton'} {'Gauss'} {'Euclid'} {'Lagrange'}
str = strjoin(C,', ')
str = 'Newton, Gauss, Euclid, Lagrange'
Join Character Vectors with Multiple Different Delimiters
Specify multiple different delimiters in a cell array of character vectors. The delimiter
cell array must have one fewer element than C
.
C = {'one','two','three'}; str = strjoin(C,{' + ',' = '})
str = 'one + two = three'
Input Arguments
C
— Input text
1
-by-n
cell array of character
vectors | 1
-by-n
string array
Input text, specified as a 1
-by-n
cell array of
character vectors or string array.
Example: {'The','rain','in','Spain'}
Example: ["Four","score","and","seven"]
Data Types: cell
| string
delimiter
— Delimiting characters
character vector | 1
-by-n
cell array of character
vectors | 1
-by-n
string array
Delimiting characters, specified as a character vector, a
1
-by-n
cell array of character
vectors, or a 1
-by-n
string
array.
If
delimiter
is a character vector, thenstrjoin
formsstr
by insertingdelimiter
between each element ofC
. Thedelimiter
input can include any of these escape sequences:\\
Backslash
\0
Null
\a
Alarm
\b
Backspace
\f
Form feed
\n
New line
\r
Carriage return
\t
Horizontal tab
\v
Vertical tab
If
delimiter
is a cell array of character vectors, then it must contain one fewer element thanC
. Each element in the cell array must contain a character vector.strjoin
formsstr
by interleaving the elements ofdelimiter
andC
. All characters indelimiter
are inserted as literal text, and escape sequences are not supported.
Example: ', '
Example: {',','
'}
Data Types: char
| cell
| string
Tips
The
join
function is recommended to join elements of a string array.
Extended Capabilities
C/C++ Code Generation
Generate C and C++ code using MATLAB® Coder™.
Usage notes and limitations:
Input text must be a string scalar or a cell array of character vectors.
Generated code returns an empty output as a 1-by-0 character array.
Thread-Based Environment
Run code in the background using MATLAB® backgroundPool
or accelerate code with Parallel Computing Toolbox™ ThreadPool
.
This function fully supports thread-based environments. For more information, see Run MATLAB Functions in Thread-Based Environment.
Version History
Introduced in R2013a
Ouvrir l'exemple
Vous possédez une version modifiée de cet exemple. Souhaitez-vous ouvrir cet exemple avec vos modifications ?
Commande MATLAB
Vous avez cliqué sur un lien qui correspond à cette commande MATLAB :
Pour exécuter la commande, saisissez-la dans la fenêtre de commande de MATLAB. Les navigateurs web ne supportent pas les commandes MATLAB.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)