Main Content

strfind

Find substring within a string in Requirements Table block

Since R2022b

Description

k = strfind(str,substr) searches the string str for occurrences of the substring substr. The operator returns a vector that contains the starting index of each occurrence of substr in str. The search is case-sensitive. Use this operator in the Requirements Table block.

example

Examples

expand all

In a Requirements Table block, create a requirement that outputs the starting character position of the substring "world" in the string "Hello, world!". The output is 8.

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

This example shows a requirement that outputs the starting character position of the substring "world" in the string "Hello, world!".

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

Output Arguments

expand all

Starting character position of each occurrence of subStr in str, returned as a vector of doubles that contains the starting index of each occurrence of substr in str. If strfind does not find subStr, then k is an empty array.

Limitations

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

Version History

Introduced in R2022b