Main Content

String Data

Text-based values

Strings are pieces of textual data. Use strings in Stateflow® charts to control chart behavior or create natural language output. Incorporate string data in your logging, messages, and custom code workflows.

Stateflow Syntax

expand all

Create, Concatenate, and Convert

blanksCreate a character array of blanks
doubleConvert string to double precision value
isletterDetermine which characters are letters
isspaceDetermine which characters are space characters
str2doubleConvert string to double-precision value
stringCreate a string

Determine Types and Properties

isletterDetermine which characters are letters
isspaceDetermine which characters are space characters
isstringDetermine if input is string
strlengthLength of string

Find and Replace

containsDetermine if pattern is in a string
endsWithDetermine if strings end with pattern
matchesDetermine if pattern matches string
replaceFind and replace one or more substring
replaceBetweenReplace substrings between start and end points
startsWithDetermine if strings start with pattern
strfindFind strings within other strings
strrepFind and replace substrings

Edit

eraseDelete substrings within strings
eraseBetweenDelete substring between start and end points
extractAfterExtract substring after specified positions
extractBeforeExtract substring before specified positions
insertAfterInsert string after specified substring
insertBeforeInsert string before specified substring
lowerConvert string to lowercase
plusAppend strings
reverseReverse order of characters in strings
stripRemove leading and trailing characters from string
strtrimRemove leading and trailing white space from a string
upperConvert a string to uppercase

Compare

matchesDetermine if pattern matches string
strcmpCompare strings
strcmpiCompare strings (case insensitive)
strncmpCompare first n characters of strings (case sensitive)
strncmpiCompare first n characters of strings (case insensitive)
ascii2strConvert array of type uint8 to string
str2asciiConvert string to array of type uint8
str2doubleConvert string to double-precision value
strcatConcatenate strings
strcmpCompare strings
strcpyAssign string value
strlenDetermine length of string
substrExtract substring from string
tostringConvert numeric value to string

Topics

Manage Textual Information by Using Strings

Use text strings in Stateflow charts.

Log String Data to the Simulation Data Inspector

View text strings in the Simulation Data Inspector and in the MATLAB® workspace.

Send Messages with String Data

Communicate between charts by using messages with string payloads.

Featured Examples