Main Content

extractBefore

Extract substring before position in Requirements Table block

Since R2022b

Description

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.

example

Examples

expand all

In a Requirements Table block, create a requirement that extracts the characters in the string "Hello, world!" before the substring ",". The output is "Hello".

y = extractBefore("Hello, world!",",")

This example shows a requirement that extracts the characters in the string "Hello, world!" before the substring ",".

In a Requirements Table block, create a requirement that extracts the characters in the string "Hello, world!" before the sixth character. The output is "Hello".

y = extractBefore("Hello, world!",6)

This example shows a requirement that extracts the characters in the string "Hello, world!" before the 6th character.

Input Arguments

expand all

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

Example: "Hello"

Data Types: string

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

Example: "Hello"

Data Types: string

Character position, specified as a positive integer.

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

Output Arguments

expand all

Output string, returned as a string scalar.

Limitations

  • This operator does not support the use of Simulink.Bus object fields.

Version History

Introduced in R2022b