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. To convert text to string arrays, use the string function.
For more information, see Represent Text with Character and String Arrays or watch Using String Arrays for Text Data.
string |
Create string array |
strings |
Create array of strings with no characters |
join |
Combine strings, or merge two tables or timetables by rows using key variables |
char |
Convert to character array |
cellstr |
Convert to cell array of character vectors |
blanks |
Create character array of blanks |
newline |
Create newline character |
contains |
Determine if pattern is in string |
count |
Count occurrences of pattern in string |
endsWith |
Determine if string ends with pattern |
startsWith |
Determine if string starts with pattern |
strfind |
Find one string within another |
sscanf |
Read formatted data from string |
replace |
Find and replace substrings in string array |
replaceBetween |
Replace substrings identified by indicators that mark their starts and ends |
strrep |
Find and replace substring |
join |
Combine strings, or merge two tables or timetables by rows using key variables |
split |
Split strings in string array, or split calendar duration into numeric and duration units |
splitlines |
Split string at newline characters |
strjoin |
Join text in array |
strsplit |
Split string at specified delimiter |
strtok |
Selected parts of string |
erase |
Delete substrings within strings |
eraseBetween |
Delete substrings between indicators that mark starts and ends of substrings |
extractAfter |
Extract substring after specified position |
extractBefore |
Extract substring before specified position |
extractBetween |
Extract substrings between indicators that mark starts and ends of substrings |
insertAfter |
Insert string after specified substring |
insertBefore |
Insert string before specified substring |
pad |
Add leading or trailing characters to strings |
strip |
Remove leading and trailing characters from string |
lower |
Convert string to lowercase |
upper |
Convert string to uppercase |
reverse |
Reverse order of characters in string |
deblank |
Remove trailing whitespace from end of string or character array |
strtrim |
Remove leading and trailing whitespace from string array or character array |
strjust |
Justify string or character array |
regexp |
Match regular expression (case sensitive) |
regexpi |
Match regular expression (case insensitive) |
regexprep |
Replace text using regular expression |
regexptranslate |
Translate text into regular expression |
Represent Text with Character and String Arrays
Store and manipulate text using either character arrays or string arrays.
Analyze Text Data with String Arrays
This example shows how to analyze text data with string arrays. It shows how to store, split, and sort text, and how to compute and collect statistics for text in a string array.
Test for Empty Strings and Missing Values
Test string arrays for empty strings and missing values.
Compose character arrays or string arrays that include ordinary text and data formatted to your specification.
MATLAB provides several functions to search for, replace, or extract text in string arrays and character vectors.
Compare and inspect character arrays and string arrays.
Regular expressions are a versatile way to search and replace text.