REPLACE¶
Replaces characters in a string.
Signature¶
┌─────────┐
IN1 ─┤ │
IN2 ─┤ │
│ REPLACE ├─ OUT
L ─┤ │
P ─┤ │
└─────────┘
FUNCTION REPLACE : ANY_STRING
VAR_INPUT
IN1 : ANY_STRING;
IN2 : ANY_STRING;
L : ANY_INT;
P : ANY_INT;
END_VAR
END_FUNCTION
The return type matches the input type. REPLACE accepts STRING
for IN1 and IN2; L and P are INT. Both string inputs must
share the same type.
Inputs
Name |
Type |
Description |
|---|---|---|
|
|
The source string. |
|
|
The replacement string. |
|
|
Number of characters in IN1 to replace. |
|
|
Starting position (1-based). |
Outputs
Name |
Type |
Description |
|---|---|---|
Return value |
|
IN1 with L characters from position P replaced by IN2. Same type as the input strings. |
Description¶
REPLACE(IN1, IN2, L, P) replaces L characters in IN1 with
IN2 starting at position P. Positions are 1-based.
The replacement string IN2 does not need to be the same length as the portion being replaced.
Example¶
result := REPLACE('Hello World', 'Earth', 5, 7); (* result = 'Hello Earth' *)
result := REPLACE('ABCDE', 'XY', 2, 2); (* result = 'AXYDE' *)
See Also¶
References¶
IEC 61131-3 §2.5.1.5.7