FIND (String Search)
Finds position of a substring within a string; returns 0 if not found.
The FIND function searches for the first occurrence of a substring within a source string and returns the starting position (1-based index). If the substring is not found, it returns 0. FIND is essential for parsing variable-format data, searching for delimiters in communication strings, and validating string content in PLC programs.
Parameters
Inputs
| Name | Type | Description |
|---|---|---|
| IN1 | STRING | Source string to search in |
| IN2 | STRING | Substring to search for |
Outputs
| Name | Type | Description |
|---|---|---|
| OUT | INT | Position of first occurrence (1-based), 0 if not found |
Structured Text Example
// Find delimiter position
Comma_Pos := FIND(IN1 := CSV_Line, IN2 := ',');
IF Comma_Pos > 0 THEN
First_Field := LEFT(IN := CSV_Line, L := Comma_Pos - 1);
END_IF;
// Check if string contains error
Has_Error := FIND(IN1 := Response, IN2 := 'ERR') > 0;20 Production-Ready Ladder Logic Templates
Stop writing the same rungs from scratch. Get copy-paste-ready templates for motor control, PID loops, safety interlocks, conveyors, and more.
Platform-Specific Implementation
Siemens (TIA Portal)
Use FIND instruction in TIA Portal. Case-sensitive search.
Allen-Bradley (Studio 5000)
Use FIND instruction in Studio 5000.
CODESYS
Use FIND() function in ST.
Common Applications
- Delimiter-based string parsing
- Substring validation
- Protocol response parsing
- Barcode data extraction
- Error string detection
Frequently Asked Questions
What is FIND (String Search) in PLC programming?
Finds position of a substring within a string; returns 0 if not found. The FIND function searches for the first occurrence of a substring within a source string and returns the starting position (1-based index). If the substring is not found, it returns 0.
What are common applications of FIND (String Search)?
FIND (String Search) is commonly used for: Delimiter-based string parsing, Substring validation, Protocol response parsing, Barcode data extraction, Error string detection.
How do I use FIND (String Search) in different PLC platforms?
Siemens: Use FIND instruction in TIA Portal. Case-sensitive search. Allen-Bradley: Use FIND instruction in Studio 5000. CODESYS: Use FIND() function in ST.
Related Function Blocks
LEFT (Left String Extract)
Extracts a specified number of characters from the beginning of a string.
View Reference →RIGHT (Right String Extract)
Extracts a specified number of characters from the end of a string.
View Reference →CONCAT (String Concatenation)
Joins two or more strings into a single combined string.
View Reference →Stop Writing Ladder Logic From Scratch
Get 20 production-ready ladder logic templates for $29 -- download instantly and use them on your next project today.
Instant download - 30-day money-back guarantee - Use on unlimited projects