Main Content

String Contains, String Starts With, String Ends With

Determine if string contains, starts with, or ends with pattern

Since R2020a

  • String Contains block

Libraries:
Simulink / String

Description

The String Contains, String Starts With, and String Ends With blocks determine if a string (str) contains, starts with, or ends with a pattern (sub).

The String Contains, String Starts With, and String Ends With blocks are identical. When Function is set to Contains, the block determines if the string contains a specified pattern. When Function is set to Starts with, the block determines if the string starts with a specified pattern. When Function is set to Ends with, the block determines if the string ends with a specified pattern.

Ports

Input

expand all

String to search for the pattern in, specified as a scalar.

Data Types: string

String pattern to search for in string, specified as a scalar.

Data Types: string

Output

expand all

Whether the string pattern was detected, returned as detected (1) or not detected (0).

Data Types: Boolean

Parameters

expand all

Case sensitivity for the pattern detection:

on

Consider string case when searching for the pattern.

off

Do not consider string case when searching for the pattern.

Programmatic Use

Block Parameter: CaseSensitive
Type: character vector
Values: 'on' | 'off'
Default: 'on'

Pattern search function, specified as:

  • Contains

    Search for the pattern anywhere in the string. This is the default for the String Contains block.

  • Starts with

    Search for the pattern only at the beginning of the string. This is the default for the String Starts With block.

  • Ends with

    Search for the pattern only at the end of the string. This is the default for the String Ends With block.

Programmatic Use

Block Parameter: Function
Type: character vector
Values: 'Contains' | 'Starts with' | 'Ends with'
Default: 'Contains' for String Contains block, 'Starts with' for String Starts With block, 'Ends with' for String Ends With block

Block Characteristics

Data Types

Boolean | string

Direct Feedthrough

yes

Multidimensional Signals

no

Variable-Size Signals

no

Zero-Crossing Detection

no

Extended Capabilities

C/C++ Code Generation
Generate C and C++ code using Simulink® Coder™.

Version History

Introduced in R2020a