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
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,
str = "Greetings friend". To convert
data to string arrays, use the
|Convert to cell array of character vectors|
|Create character array of blanks|
|Create newline character|
|Convert data into formatted string array|
|Format data into string|
|Concatenate strings horizontally|
|Determine if input is character array|
|Determine if input is cell array of character vectors|
|Determine if input is string array|
|Determine if input is string array with one element|
|Determine if pattern is in string|
|Count occurrences of pattern in string|
|Determine if string ends with pattern|
|Determine if string starts with pattern|
|Find one string within another|
|Read formatted data from string|
|Delete substrings within strings|
|Delete substrings between indicators that mark starts and ends of substrings|
|Extract substring after specified position|
|Extract substring before specified position|
|Extract substrings between indicators that mark starts and ends of substrings|
|Insert string after specified substring|
|Insert string before specified substring|
|Add leading or trailing characters to strings|
|Remove leading and trailing characters from string|
|Convert string to lowercase|
|Convert string to uppercase|
|Reverse order of characters in string|
|Remove trailing whitespace from end of string or character array|
|Remove leading and trailing whitespace from string array or character array|
|Justify string or character array|
Store and manipulate text using either character arrays or 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 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.