Block that inserts a STRING in certain position of another, 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 insertion will be performed |
|
STR2 |
STRING |
STRING to be inserted |
|
POS |
BYTE |
Position where STR2 will be inserted |
|
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.
An insertion in STR1 from the defined position POS of the STR2 content is performed.
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 characters 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, an insertion of STR2 into STR1 from position 2 is done, and the result is sent to DST_10. When the block is ended successfully, the DONE output is activated.

In the example above, is done of an insertion of STR2 into STR1 from position 4, and the result is sent to DST_6. Since the size of DST_6 is 6, the last two characters copied are discarded. The block ends successfully, Done output is activated.
Example in ST
The example below displays the instructions for applying the example above in the ST language.
VAR STR1 : STRING := '2232'; STR2 : STRING := '1'; POS : BYTE; DST_2 : STRING; END_VAR
DST_2 := FB_STR_INSERT( EN:=DI1, STR1:=STR1, STR2:=STR2, POS:=POS, Done=>DO1);
|
|---|