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

STR_COMPARE

Comparação de Strings

Previous pageReturn to chapter overviewNext page

Block that performs the comparison between STRINGs.

 

Ladder Representation

 

STR_COMPARE_block

 

Block Structure

 

Variable Type

Name

Data Type

Description

VAR_INPUT

EN

BOOL

Block enabling

STR1

STRING

First STRING of the comparison

STR2

STRING

Second STRING of the comparison

SENSITIVE

BOOL

Selects whether the comparison will be case insensitive or not

VAR_OUTPUT

DONE

BOOL

Output enabling

COMP

BYTE

Value of comparison

 

Operation

 

This block remains active as long as EN is at TRUE level by updating the value of COMP according to the input STRINGs. The SENSITIVE input with value TRUE forces the comparison to consider uppercase and lowercase letters, while a FALSE value ignores this differentiation. The values that COMP can take are:

0, if both are the same;
-1, if STR1 comes first in alphabetical order;
1, if STR1 comes after in alphabetical order.

The comparison takes into account the values of the ASCII table for the characters.

 

The DONE value forwards to the next Ladder block the EN value when the operation is completed.

 

Compatibility

 

Device

Version

PLC300

2.10 or higher

 

Block Flowchart

 

STR_COMPARE_flowchart

 

Example in Ladder

 

STR_COMPARE_example01

 

In the above example, the ASCII code for 'a', first character of STR1, is smaller than that of 'c', first character of STR2. Thus, COMP receives the value -1. When the block is finished successfully, the DONE output is activated.

 

STR_COMPARE_example02

 

In the above example, the ASCII code for 'a', first character of STR1, is greater than that of '.', first character of STR2. Thus, COMP receives the value 1. When the block is ended successfully, the DONE output is activated.

 

STR_COMPARE_example03

 

In the example above, STR1 and STR2 are the same. Therefore, COMP receives the value of 0. When the block ends successfully, Done output is activated.

 

STR_COMPARE_example04

 

In the example above, STR1 and STR2 are the same, disregarding uppercase and lowercase (SENSITIVE with FALSE value). Therefore, COMP receives the value of 0. When the block ends successfully, Done output is activated.

 

STR_COMPARE_example05

 

In the example above, STR1 and STR2 are the different, considering uppercase and lowercase (SENSITIVE with FALSE value). The ASCII code for 'a', first character of STR1, is greater than that of 'A', first character of STR2. Thus, COMP receives the value 1. When the block is ended successfully, the 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 := 'abc';

   STR2 : STRING := 'AbC';

   SENSITIVE : BOOL := 0;

   COMP : SINT;

END_VAR

 

COMP := FB_STR_COMPARE(

   EN:=DI1,

   STR1:=STR1,

   STR2:=STR2,

   SENSITIVE:=SENSITIVE,

   Done=>DO1);