INSERT - Inserts one string into another string

Help Contents

Introduction

Inserts a string into another string at a position in the string.

Informal Syntax:

INSERT( In1, In2, P )

Formal Syntax:

INSERT( In1:=expression, In1:=expression, P:=Expression )

Parameters

ParameterTypeDescription
In1ANY_STRINGThe target string.
In2ANY_CHARSThe string or character to insert.
PANY_INTThe insert position (1-based).

The function is overloaded and accepts a range of types for the In1 and In2 parameters:

Position P is 1-based, where 1 represents the first character in the string, 2 represents the second character in the string, and so on.

If position P is zero or negative, parameter In2 is inserted at the start of In1. If position P is greater than the length of In1, parameter In2 is inserted at the end of In1.

Return Value

The function returns the result of string or character In2 inserted into string In1 at position P.

The type of the return value is the same type as the In1 parameter.

Examples

ExampleReturn Value
INSERT('Item', '*', 0 )STRING#'*Item'
INSERT('Item', '*', 1 )STRING#'*Item'
INSERT('Item', '*', 3 )STRING#'It*em'
INSERT('Item', '*', 5 )STRING#'Item*'
INSERT('Item', '*', 6 )STRING#'Item*'

Standards Compliance

Table 29.6 - IEC 61131-3 Second Edition.

Table 34.6 - IEC 61131-3 Third Edition.

Note: The function allows negative values for the P parameter. The IEC 61131-3 standard states this should be an error.

Note: The function allows the P parameter to be a location outside the input string. The IEC 61131-3 standard states this should be an error.

Note: The function allows different string types as parameters. The IEC 61131-3 Third Edition standard states this should be an error.

Further Information

String Functions

To learn about other String Functions.

Common Elements

To learn about other IEC 61131-3 Common Elements.

Glossary

For the meaning of terms used in Fernhill SCADA.