Characters and Strings
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. You can create strings using double quotes, such as
str = "Greetings friend"
. To convert data to string arrays, use thestring
function.
For more information, see Text in String and Character Arrays or watch Using String Arrays for Text Data.
Functions
Topics
- Text in String and Character Arrays
Store and manipulate text using either string arrays or character 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.
- Formatting Text
Compose character arrays or string arrays that include ordinary text and data formatted to your specification.
- Search and Replace Text
MATLAB provides several functions to search for, replace, or extract text in string arrays and character vectors.
- Unicode and ASCII Values
MATLAB stores all characters as Unicode characters. Both strings and character vectors use the same encoding. You can convert characters to their Unicode code values, and numbers to characters.
- Hexadecimal and Binary Values
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.