Topic: DMD0166

Help File Version: 2.10.0.636

STRFIND - Find within String


The Find within String (STRFIND) instruction will search the target string for a match to a second String or a Sting LiteralClosed Zero or more characters enclosed in double quotes, as in "hello", and may include both simple escape sequences (such as \t for the tab character) and hexadecimal data (such as 0xAA).. If the specified 'Search from' is 'Beginning to end', and the STRFIND operation is successful, the 'Where Found' value can be used programmatically as the Offset value in the Get Sub-String (STRSUB), Delete Sub-String (STRDELETE), and Insert Sub-String (STRINSERT) instructions.

 

 


Parameters:

Note: Use the F9 key or click the 'three dot box' at the right edge of the parameter field to open the Default Element Selection Tool (the Element Picker or the Element Browser) or use the Down-Arrow key (Auto-Complete) on any parameter field to see a complete list of the memory locations that are valid for that parameter of the instruction.

 

Find within - this can be any User-defined or System-defined String.

 


Search From - designates the direction of the search
 

  • Beginning to end - select this option to begin the search at the first character in the Find within string.
     

  • End to beginning - select this option to begin the search at the last character in the Find within string.

 


Case Sensitive

 

  • Yes, upper / lower case are different - select this option if the comparison needs to distinguish between upper case and lower case versions of the same characters, that is, "A" is NOT the same as "a".

     

  • No, upper / lower case are equal - select this option if the comparison does not need to distinguish between upper case and lower case versions of the same characters, that is, "A" is the same as "a".

 


In Offset: Start / Out Offset: Where Found - is an input AND output parameter. Both the In Offset: Start and Out Offset: Where Found values are 0-based.

 

As the input parameter (In Offset: Start) specifies the character offset into the Find within string to begin the search.

 

As the output parameter (Out Offset: Where Found) stores the 0-based character offset in the Find within String where the Find Text / String was found if the operation was successful. If there are multiple potential matches, this will contain the offset of the first match. The offset value is relative to the end of the String where the search begins. For example, if the String SS0 contains "ABCDEFG", a STRFIND that searched for "C" will find it at offset 2 when searching from 'Beginning to end', but will find it at offset 4 when searching from 'End to beginning'. If no match is found this value will be set to -1.

 


Set If Found - select this option to have the designated bit set ON if a match is found. This can be any writable bit location.

 

Set If Not Found - select this option to have the designated bit set ON if a match is not found. This can be any writable bit location.

 


Find Text / String - is the text to look for in the Find within String. This can be any String element, or a Sting LiteralClosed Zero or more characters enclosed in double quotes, as in "hello", and may include both simple escape sequences (such as \t for the tab character) and hexadecimal data (such as 0xAA)..
 

  • Exact sequence - select this option to specify that all of the characters of the Find Text / String must be found in the exact order in the Find within String to constitute a match
     

  • Any one of these characters - select this option to specify that finding any one of the characters of the Find Text / String found in any order in the Find within String will constitute a match.

 


Input Leg selects which of the following power-flow conditions will cause this instruction to run:

 

  • Edge Triggered means the instruction will run to completion each time the input ladder logic transitions from OFF to ON.
     
  • Power flow enabled means the instruction will run repeatedly as long as the input ladder logic remains ON.

 


Status Display:

 

The Status display will only show as many of the characters of the Find within String and Find Text / String as will fit within the borders of the instruction, typically this is about 50 characters.

 


See Also:

STR2REAL - Convert String to Real

 

STR2INT - Convert String to Integer

 

STRCASE - Convert String to UPPER / lower Case

 

STRCLEAR - Clear Strings

 

STRCMP - String Compare

 

STRCOPY - Copy String

 

STRCOPYR - Copy a Range of Strings


STRDELETE - Delete Substring

 

STRFIND - Find within String

 

STRINSERT - Insert Substring

 

STRPRINT - Print to String

 

STRSUB - Get Substring

 

STRTRIM - Trim Whitespace

 

STRTRUNC - Truncate String

 


Related Topics:

String Functions Overview

 

String Scripting Language Reference

 


Example: