Character arrays and string arrays provide storage for text data in MATLAB®.
A character array is a sequence of characters, just as a numeric array is a sequence of numbers. A typical use is to store short pieces of text as character vectors, such as c = 'Hello World'.
A string array is a container for pieces of text. String arrays provide a set of functions for working with text as data. Starting in R2017a, you can create strings using double quotes, such as str = "Greetings friend". To convert data to string arrays, use the string function.
For more information, see Text in String and Character Arrays or watch Using String Arrays for Text Data.
char |
Character array |
cellstr |
Convert to cell array of character vectors |
blanks |
Create character array of blanks |
newline |
Create newline character |
compose |
Format data into multiple strings |
sprintf |
Format data into string or character vector |
strcat |
Concatenate strings horizontally |
append |
Combine strings |
convertCharsToStrings |
Convert character arrays to string arrays, leaving other arrays unaltered |
convertStringsToChars |
Convert string arrays to character arrays, leaving other arrays unaltered |
convertContainedStringsToChars |
Convert string arrays at any level of cell array or structure |
double |
Double-precision arrays |
string |
String array |
str2double |
Convert strings to double precision values |
num2str |
Convert numbers to character array |
ischar |
Determine if input is character array |
iscellstr |
Determine if input is cell array of character vectors |
isstring |
Determine if input is string array |
isStringScalar |
Determine if input is string array with one element |
contains |
Determine if pattern is in strings |
matches |
Determine if pattern matches strings |
count |
Count occurrences of pattern in strings |
endsWith |
Determine if strings end with pattern |
startsWith |
Determine if strings start with pattern |
strfind |
Find strings within other strings |
sscanf |
Read formatted data from strings |
replace |
Find and replace one or more substrings |
replaceBetween |
Replace substrings between start and end points |
strrep |
Find and replace substrings |
erase |
Delete substrings within strings |
eraseBetween |
Delete substrings between start and end points |
extractAfter |
Extract substrings after specified positions |
extractBefore |
Extract substrings before specified positions |
extractBetween |
Extract substrings between start and end points |
insertAfter |
Insert strings after specified substrings |
insertBefore |
Insert strings before specified substrings |
pad |
Add leading or trailing characters to strings |
strip |
Remove leading and trailing characters from strings |
lower |
Convert strings to lowercase |
upper |
Convert strings to uppercase |
reverse |
Reverse order of characters in strings |
deblank |
Remove trailing whitespace from ends of strings |
strtrim |
Remove leading and trailing whitespace from strings |
strjust |
Justify strings |
regexp |
Match regular expression (case sensitive) |
regexpi |
Match regular expression (case insensitive) |
regexprep |
Replace text using regular expression |
regexptranslate |
Translate text into regular expression |