Main Content

substr

Extract substring from string

Description

example

dest = substr(str,i,n) returns the substring of length n starting at the i-th character of string str. Use zero-based indexing.

Note

The operator substr is supported only in Stateflow® charts that use C as the action language.

Examples

expand all

Extract substring "Stateflow" from a longer string.

str = "Stateflow, rule the waves!";
dest = substr(str,0,9);

Stateflow chart that uses the substr operator in a state.

Tips

  • Use zero-based indexing.

  • Enclose literal strings with single or double quotes.

Introduced in R2018b