Main Content

extractBefore

Extract substring before position

Description

example

newStr = extractBefore(str,subStr) returns the substring of str that ends before the first occurrence of the substring subStr.

example

newStr = extractBefore(str,pos) returns the substring of str that ends before the character position pos.

Note

The extractBefore operator is not supported in Stateflow® charts that use C as the action language. For similar functionality, use substr.

Examples

expand all

Extract substring "Hello" from a longer string.

str = "Hello, world!";
newStr = extractBefore(str,", world");

Stateflow chart that uses the extractBefore operator in a state.

Extract substring "Hello" from a longer string.

str = "Hello, world!";
newstr = extractBefore(str,6);

Stateflow chart that uses the extractBefore operator in a state.

Input Arguments

expand all

Input string, specified as a string scalar. Enclose literal strings with double quotes.

Example: "Hello"

Substring, specified as a string scalar. Enclose literal strings with double quotes.

Example: "Hello"

Character position, specified as a positive integer.

Limitations

Version History

Introduced in R2021b