Main Content

startsWith

Determine if string starts with substring

Description

example

tf = startsWith(str,substr) returns 1 (true) if the string str starts with the substring substr, and returns 0 (false) otherwise.

example

tf = startsWith(str,substr,IgnoreCase=true)checks if str starts with substr, ignoring any differences in letter case.

Note

The startsWith operator is not supported in Stateflow® charts that use C as the action language.

Examples

expand all

Return a value of 0 (false) because the string "Hello, world!" does not start with the substring "hello".

str = "Hello, world!";
substr = "hello";
x = startsWith(str,substr);

Stateflow chart that uses the startswith operator in a state.

Return a value of 1 (true) because the string "Hello, world!" starts with the substring "hello" when you ignore case.

str = "Hello, world!";
substr = "hello";
x = startsWith(str,substr,IgnoreCase=true);

Stateflow chart that uses the startswith 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"

Limitations

Version History

Introduced in R2021b