Main Content

substr

Extract substring from string

Description

newStr = substr(str,pos,length) returns the substring of str that starts at the character position pos and is length characters long. Use zero-based indexing.

example

Note

The operator substr is supported only in Stateflow® charts that use C as the action language. In charts that use MATLAB® as the action language, use extractAfter or extractBefore.

Examples

expand all

Extract substring "world" from a longer string.

str = "Hello, world!";
newStr = substr(str,7,5);

Stateflow chart that uses the substr operator in a state.

Tips

  • Use zero-based indexing.

  • Enclose literal strings with single or double quotes.

Version History

Introduced in R2018b