String instructions
274
Part II IEC Instructions
FIND
Find string's position
To add an enable input and enable output to the instruction, select [With EN/ENO] from the
"Instructions" pane (LD, FBD or IL editor). To reuse an instruction select "Recently used" from the
context menu or press <Ctrl>+<Shift>+<v> in the programming window.
PLC types
Availability of FIND (see page 1326)
If the strings are longer than the length defined for the input variables
(input_string_1 and input_string_2) in the field "Type", an error occurs
(see Special Internal Relays for Error Handling).
The number of steps may vary depending on the PLC and parameters
used, see also Table of Code Intensive Instructions in the online help.
(up to 200 steps)
Data type I/O Function
STRING 1st input input string
STRING 2nd input string that is searched for in the input string
INT output position at which the string searched for is found
No. IEC address Set If
R9007 %MX0.900.7 permanently
R9008 %MX0.900.8 for an instant
input strings are longer than the length
defined for the input variables in the field
"Type"
Description
FIND returns the position at which the second input string first occurs in the first input string. The
result is written into the output variable. If the second input string does not occur in the first input
string, the value ZERO is returned.
Data types
Error flags
Example
In this example, the same POU header is used for all programming languages. For an example
using IL (instruction list), please refer to the online help.
POU header
All input and output variables used for programming this function have been declared in the POU
header.
In this example the input variables (input_string_1 and input_string_2) have been declared.
Instead, you may enter the strings ('Ideas for life' and 'for') directly into the function. The strings
have to be put in inverted commas, both in the POU header and in the function.
Body
Input_string_2 (‘for’) is searched in input_string_1 (‘Ideas for life’). The position of the first
occurrence (7) is written into output_value.