Documentation

This is machine translation

Translated by Microsoft
Mouse over text to see original. Click the button below to return to the English verison of the page.

라이선스가 부여된 사용자만 번역 문서를 볼 수 있습니다. 번역 문서를 보려면 로그인하십시오.

Characters and Strings

Text in character arrays and string arrays

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.

Functions

String Arrays

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

Character Arrays

char Convert to character array
cellstr Convert to cell array of character vectors
blanks Create character array of blanks
newline Create newline character

Character or String Arrays

compose Convert data into formatted string array
sprintf Format data into string
strcat Concatenate strings horizontally

Data Type

ischar Determine if item is character array
iscellstr Determine if input is cell array of character vectors
isstring Determine if input is string array

Text Properties

strlength Length of strings in string array
isstrprop Determine if string is of specified category
isletter Array elements that are alphabetic letters
isspace Array elements that are space characters
symvar Determine symbolic variables in expression

Find

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

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
strcmp Compare strings
strcmpi Compare strings (case insensitive)
strncmp Compare first n characters of strings (case sensitive)
strncmpi Compare first n characters of strings (case insensitive)
regexp Match regular expression (case sensitive)
regexpi Match regular expression (case insensitive)
regexprep Replace text using regular expression
regexptranslate Translate text into regular expression

Topics

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.

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.

Compare Text

Compare and inspect character arrays and string arrays.

Regular Expressions

Regular expressions are a versatile way to search and replace text.

Was this topic helpful?