Main Content

extractBefore

Extract substring before specified positions

Description

example

newStr = extractBefore(str,pat) extracts the substring that begins with the first character of str and ends before the substring specified by pat. If pat occurs multiple times in str, then newStr is str from the start of str up to the first occurrence of pat.

example

newStr = extractBefore(str,pos) extracts the substring that begins with the first character of str and ends before the position specified by pos.

Note

Only Stateflow® charts that use MATLAB® as the action language support the extractBefore operator.

Examples

expand all

Select the text that occurs before a substring.

h = "Hello, world!"
pat = ","
x = extractBefore(h, pat)

Stateflow chart that uses the extractBefore operator in a state.

Results from stateflow chart that uses the extractBefore operator in a state.

Select the text that occurs after a position.

h = "Hello, world!"
x = extractAfter(h, 6)

Stateflow chart that uses the extractbefore operator in a state.

Results from stateflow chart that uses the extractbefore operator in a state.

Limitations

Introduced in R2021b