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|
|Format data into multiple strings|
|Format data into string or character vector|
|Concatenate strings horizontally|
|Convert character arrays to string arrays, leaving other arrays unaltered|
|Convert string arrays to character arrays, leaving other arrays unaltered|
|Convert string arrays at any level of cell array or structure|
|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 strings|
|Determine if pattern matches strings|
|Count occurrences of pattern in strings|
|Determine if strings end with pattern|
|Determine if strings start with pattern|
|Find strings within other strings|
|Read formatted data from strings|
|Delete substrings within strings|
|Delete substrings between start and end points|
|Extract substrings after specified positions|
|Extract substrings before specified positions|
|Extract substrings between start and end points|
|Insert strings after specified substrings|
|Insert strings before specified substrings|
|Add leading or trailing characters to strings|
|Remove leading and trailing characters from stringS|
|Convert strings to lowercase|
|Convert strings to uppercase|
|Reverse order of characters in strings|
|Remove trailing whitespace from ends of strings|
|Remove leading and trailing whitespace from strings|
Store and manipulate text using either string arrays or character arrays.
Adopt string arrays as a text data type in your own code, following these guidelines.
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.
Compose character arrays or string arrays that include ordinary text and data formatted to your specification.
Specify hexadecimal and binary values either as literals or as text. Hexadecimal and binary literals are stored as integers. You can convert text representing hexadecimal and binary values to numbers, and numbers to text representations.
Regular expressions are a versatile way to search and replace text.