Navigation:  Equipments (Devices) > PLC200 > Program > String >

STR_COPY

Cópia de Strings

Previous pageReturn to chapter overviewNext page

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

 

Ladder Representation

 

STR_COPY_block

 

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.

 

wpshelp_common_fig_note

NOTE!

POS is treated with index "based one". That is, POS = 1 references the first position of STR.

 

wpshelp_common_fig_note

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

 

STR_COPY_flowchart

 

Example in Ladder

 

STR_COPY_example01

 

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

 

STR_COPY_example02

 

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.

 

STR_COPY_example03

 

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.

 

STR_COPY_example04

 

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.

 

STR_COPY_example05

 

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);