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

IN1

ANY_STRING

The source string.

IN2

ANY_STRING

The replacement string.

L

INT

Number of characters in IN1 to replace.

P

INT

Starting position (1-based).

Outputs

Name

Type

Description

Return value

ANY_STRING

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