Block that searches for the first occurrence of one STRING in another, returning the position of this occurrence.
Ladder Representation

Block Structure
Variable Type |
Name |
Data Type |
Description |
VAR_INPUT |
EN |
BOOL |
Block enabling |
STR1 |
STRING |
STRING where the search will be performed |
|
STR2 |
STRING |
STRING to be searched |
|
START |
BYTE |
Initial search position |
|
VAR_OUTPUT |
DONE |
BOOL |
Output enabling |
POS |
BYTE |
Position where STR2 was found |
Operation
This block remains active as long as EN is at TRUE level, updating the value of POS according to the input parameters.
A search in STR1 is performed, from the START position, by an occurrence of STR2.
If it is found, it inserts into the POS the occurrence of this position, while DONE forwards to the next Ladder block the value of EN when ending the operation.
If it is not found or START receives value zero, DONE remains FALSE and POS remains unchanged.
|
NOTE! POS is treated with index "based one". That is, POS = 1 references the first position of STR. |
Compatibility
Device |
Version |
PLC300 |
2.10 or higher |
Block Flowchart

Example in Ladder

In the above example, a search for STR2 in STR1 from position 1 is done. Since STR2 is found in position 1, POS receives 1. The block ends successfully, the DONE output is activated.

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

In the above example, a search for STR2 in STR1 from position 2 is done. Since STR2 is found in position 3, POS receives 3. The block ends successfully, the DONE output is activated.

In the above example, a search for STR2 in STR1 from position 2 is done. Since STR2 is found in position 3, POS receives 3. The block ends successfully, the DONE output is activated.

In the above example, a search for STR2 in STR1 from position 2 is done. Since STR2 is not found, POS remains unchanged and 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 := '1212'; STR2 : STRING := '13'; START : BYTE := 2; POS : BYTE; END_VAR
POS := FB_STR_FIND( EN:=DI1, STR1:=STR1, STR2:=STR2, START:=START, Done=>DO1);
|
|---|