Block that performs a copy of a section of STR, storing the result in DST.
Ladder Representation

Block Structure
Variable Type |
Name |
Data Type |
Description |
VAR_INPUT |
EN |
BOOL |
Block enabling |
STR |
STRING |
Original STRING |
|
POS |
BYTE |
Position from which the copy will begin |
|
LEN |
BYTE |
Number of characters to be copied from POS |
|
VAR_OUTPUT |
DONE |
BOOL |
Output enabling |
DST |
BYTE |
Variable that receives the new STRING |
Operation
This block remains active as long as EN is at TRUE level, updating the value of DST according to the input parameters. DST receives a number of characters from STR1 defined by LEN from the inserted position in POS.
If POS is outside the allowable range of values (between 1 and the size of STR), 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 number of characters copied from STR, 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 example above, two characters are copied from position 1 of STR1, and the result is sent to DST_2. When the block is ended successfully, the DONE output is activated.

In the example above, zero characters are copied from position 1 of STR1, and the result is sent to DST_2. When the block is ended successfully, the DONE output is activated. Note that, when LEN is zero, the output is always built as a null STRING.

In the example above, two characters are copied from position 4 of STR1, and the result is sent to DST_2. 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 copied, without generating an error.

In the example above, three characters are copied from position 2 of STR1, and the result is sent to DST_2. Since the size of DST_2 is 2, the last character copied is 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 := 'abcd'; POS : BYTE := 2; LEN : BYTE := 3; DST_2 : STRING; END_VAR
DST_2 := FB_STR_COPY( EN:=DI1, STR:=STR1, POS:=POS, LEN:=LEN, Done=>DO1);
|
|---|