Deletes characters from a string, then inserts another string at the position of the deleted characters.
Informal Syntax:
Formal Syntax:
REPLACE( In1:=expression, In2:=expression, L:=expression, P:=expression )
Parameter | Type | Description |
---|---|---|
In1 | ANY_STRING | The target string. |
In2 | ANY_CHARS | The string to insert. |
L | ANY_INT | The number of characters to delete before the new string is inserted. |
P | ANY_INT | The replace position (1-based). |
The function is overloaded and accepts a range of types for the In1 and In2 parameters:
The return value is the result of deleting L characters at position P from string In1, followed by inserting string In2 at position P.
The type of the return value is the same as the type of the In1 parameter.
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, position P is rounded up to 1 (the first character in the string). The function REPLACE deletes L characters from string In1 at position P, then inserts string In2 also at position P.
If position P is greater than the length of the string, no characters are deleted. In this case string In2 is inserted at the end of string In1.
Example | Return Value |
---|---|
REPLACE('Account', '*', 1, 2 ) | STRING#'A*count' |
REPLACE('Modbus', 'icon', 3, 4 ) | STRING#'Modicon' |
REPLACE('Thing', '*', 3, 2 ) | STRING#'T*g' |
IEC 61131-3 Second Edition: Table 29.8.
IEC 61131-3 Third Edition: Table 34.85.
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 indicate 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.
To learn about other String Functions.
To learn about other IEC 61131-3 Common Elements.
For the meaning of terms used in Fernhill SCADA.