Main Content

Substring

Extract substring from input string signal

  • Library:
  • Simulink / String

  • Substring block

Description

The Substring block extracts a substring from the input string signal. The block extracts the substring starting from the letter corresponding to idx and includes a len number of characters starting at idx. For example, if the input string is "hello 123", input idx is 1, and input len is 5, the output is "hello". The block extracts a substring starting at 1 and the next 4 characters for a total of 5 characters (hello).

Ports

Input

expand all

Input string signal, specified as a string.

Data Types: string

Start of string to extract, specified as a positive scalar integer.

Data Types: int8 | int16 | int32 | uint8 | uint16 | uint32

Length of string to extract, specified as a scalar. If len causes the substring to extend beyond the end of the string, the output signal contains few than len characters.

Data Types: uint8 | uint16 | uint32

Output

expand all

Extracted string, specified as a scalar.

Data Types: string

Parameters

expand all

Use same maximum length as the input string source block.

on

Use same maximum length. The substring includes the characters starting from the character at idx to the end of the string.

off

Do not use same maximum length.

Dependencies

Selecting this check box enables the Output data type parameter.

Output data type, specified using the string data type to specify a string with no maximum length.

To specify a string data type with a maximum length, specify stringtype(N). For example, stringtype(31) creates a string data type with a maximum length of 31 characters.

Click the Show data type assistant button to display the Data Type Assistant, which helps you set the data type attributes. See Specify Data Types Using Data Type Assistant for more information.

Dependencies

To enable this parameter, select Inherit maximum length from input.

Extract string from idx to end of input string.

on

Extract string from idx to end of input string.

off

Do not extract string from idx to end of input string.

Dependencies

Selecting this parameter removes the third input port.

Block Characteristics

Data Types

integer | 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™.

Introduced in R2018a