Find String (FIND)
The FIND instruction locates the starting position of a specified string within another string.
The FIND instruction searches the Source string for the Search string. If the instruction finds the Search string, the Result shows the starting position of the Search string within the Source string. Otherwise the Results is zero.
Available Languages
Ladder Diagram
_v1.png/_jcr_content/renditions/original)
FactoryTalk Design Studio
DSL - Ladder Diagram and
Structured TextFIND(Source,Search,Start,Result);
Operands
There are data conversion rules for mixed data types within an instruction. See Data Conversion.
Ladder Diagram and Structured Text
Operand | Type | Format | Description | Notes |
|---|---|---|---|---|
Source | String | Tag | The string to search in | String types are:
|
Search | String | Tag | The string to find | |
Start | SINT
INT
DINT | Immediate
tag | The position in Source to start the search | Enter a number between 1 and the DATA size of the Source. |
Result | DINT
SINT
INT | Tag | The position in Source where search string was found |
See Structured Text syntax for more information on the syntax of
expressions within structured text. DescriptionThe FIND instruction searches the Source
string for the Search string. If the instruction finds the Search string, the Result shows
the starting position of the Search string within the Source string. Otherwise, the Result
is zero.
Affects Math Status Flags
No
Major/Minor Faults
A minor fault will occur if: | Fault Type | Fault Code |
|---|---|---|
The LEN value of the string tag is greater than the DATA size of the string tag. | 4 | 51 |
The Start value is invalid, or the Source string is empty. | 4 | 56 |
See Common Attributes for operand related faults.
Execution
Ladder Diagram and Structured Text
Condition | Action |
|---|---|
Prescan | N/A |
Rung-condition-in is false (Ladder Diagram only) | N/A |
Rung-condition-in is true | The instruction executes. |
Postscan | N/A |
Example
A message from a Message View contains several pieces of information. The backslash
character (\) separates each piece of information. To locate a piece of information, the
FIND instruction searches for the backslash character and records its position in
find_pos.
Structured Text
IF MV_read.EM THEN FIND(MV_msg,find,1,find_pos); MV_read.EM :=0; END_IF;
Provide Feedback