REPLACE (replace sub-string)

The REPLACE instruction replaces parts of a string with new sets of characters.
Languages supported: Function block diagram, ladder diagram, structured text.
This instruction applies to the Micro810, L20E, L50E, and L70E controllers.
REPLACE
REPLACE
REPLACE parameters
Parameter
Parameter Type
Data Type
Description
EN
Input
BOOL
Function enable.
  • TRUE: Replace parts of strings with new characters.
  • FALSE: No operation.
Applies to ladder diagram programs.
IN
Input
STRING
Any string.
Str
Input
STRING
String to be inserted (to replace NbC chars).
NbC
Input
DINT
Number of characters to be deleted.
Pos
Input
DINT
Position of the first modified character (first valid position is 1).
REPLACE
Output
STRING
Modified string. The NbC characters are deleted at position Pos, then the substring Str is inserted at this position. Can be:
  • Empty string if Pos <= 0.
  • Strings concatenation (IN+Str) if Pos is greater than the length of the IN string.
  • Initial string IN if NbC <= 0.
ENO
Output
BOOL
Enable output.
Applies to ladder diagram programs.

REPLACE examples

REPLACE function block diagram example
REPLACE function block diagram example
REPLACE ladder diagram example
REPLACE ladder diagram example
REPLACE structured text example
REPLACE structured text example
Results
Results
Replacing a part of a string with a new set of characters.
(* ST Equivalence: *) MyName := REPLACE ('Mr X JONES, 'Frank', 1, 4); (* MyName is 'Mr Frank JONES' *)
Provide Feedback
Have questions or feedback about this documentation? Please submit your feedback here.
Normal