Block that replaced a section of a STRING by another STRING, returning the resulting STRING.
Ladder Representation

Block Structure
Variable Type |
Name |
Data Type |
Description |
VAR_INPUT |
EN |
BOOL |
Block enabling |
STR1 |
STRING |
STRING where the replacement will take place |
|
STR2 |
STRING |
STRING to be inserted |
|
POS |
BYTE |
Position where STR2 will be inserted |
|
LEN |
BYTE |
Number of characters to be replaced by STR2 in STR1 |
|
VAR_OUTPUT |
DONE |
BOOL |
Output enabling |
DST |
STRING |
Resulting STRING |
Operation
This block remains active as long as EN is at TRUE level, updating the value of DST according to the input parameters.
From the position defined in POS a number of characters defined by LEN are deleted. After that, in this position, the content of STR2 is inserted.
If POS is outside the allowable range of values (between 1 and the size of STR plus one), DONE receives FALSE and DST remains unchanged.
If successful, the DONE value forwards to the next Ladder block the EN value when the operation is completed.
|
NOTE! POS is treated with index "based one". That is, POS = 1 references the first position of STR. |
|
NOTE! If the size of DST is less than the sum of the number of remaining characters of STR1 and STR2, the resulting value will be truncated. |
Compatibility
Device |
Version |
PLC300 |
2.10 or higher |
Block Flowchart

Example in Ladder

In the above example, as the value of POS is invalid, the block is not completed successfully, and the DONE output is disabled.

In the above example, as the value of POS is invalid, the block is not completed successfully, and the DONE output is disabled.

In the example above, a replacement of zero characters from the position 5 of STR1 is done by the contents of STR2, and the result is sent to DST_10. When the block is ended successfully, the DONE output is activated. Note that this block acted as a STR_INSERT.

In the example above, a replacement of zero characters from the position 2 of STR1 is done by the contents of STR2, and the result is sent to DST_10. When the block is ended successfully, the DONE output is activated. Note that this block acted as a STR_INSERT.

In the example above, a replacement of one character from the position 3 of STR1 is done by the contents of STR2, and the result is sent to DST_10. When the block is ended successfully, the DONE output is activated.

In the example above, a replacement of eight characters from the position 2 of STR1 is done by the contents of STR2, and the result is sent to DST_10. When the block is ended successfully, the DONE output is activated. Note that if POS + LEN is greater than the size of STR1, only the remaining characters from STR1 are replaced, without generating an error.
Example in ST
The example below displays the instructions for applying the example above in the ST language.
VAR STR1 : STRING := 'abcd'; STR2 : STRING := '1234'; POS : BYTE := 2; LEN : BYTE := 8; DST_10 : STRING; END_VAR
DST_10 := FB_STR_REPLACE( EN:=DI1, STR1:=STR1, STR2:=STR2, POS:=POS, LEN:=LEN, Done=>DO1);
|
|---|