LEFT (Left String Extract)
Extracts a specified number of characters from the beginning of a string.
The LEFT function extracts a specified number of characters from the beginning (left side) of a string. It is used for parsing fixed-format data, extracting prefixes, and processing communication messages where specific fields are at known positions from the start of the string.
Parameters
Inputs
| Name | Type | Description |
|---|---|---|
| IN | STRING | Source string |
| L | INT | Number of characters to extract from left |
Outputs
| Name | Type | Description |
|---|---|---|
| OUT | STRING | Extracted substring |
Structured Text Example
// Extract device code from 'DEV001-MOTOR-A' Device_Code := LEFT(IN := Device_ID, L := 6); // Result: 'DEV001' // Extract date from formatted string Date_Part := LEFT(IN := DateTime_Str, L := 10); // '2025-01-15'
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 LEFT instruction in TIA Portal.
Allen-Bradley (Studio 5000)
Use MID instruction with starting position 1.
CODESYS
Use LEFT() function in ST.
Common Applications
- Fixed-format data parsing
- Device code extraction
- Protocol header parsing
- Barcode prefix extraction
Frequently Asked Questions
What is LEFT (Left String Extract) in PLC programming?
Extracts a specified number of characters from the beginning of a string. The LEFT function extracts a specified number of characters from the beginning (left side) of a string. It is used for parsing fixed-format data, extracting prefixes, and processing communication messages where specific fields are at known positions from the start of the string.
What are common applications of LEFT (Left String Extract)?
LEFT (Left String Extract) is commonly used for: Fixed-format data parsing, Device code extraction, Protocol header parsing, Barcode prefix extraction.
How do I use LEFT (Left String Extract) in different PLC platforms?
Siemens: Use LEFT instruction in TIA Portal. Allen-Bradley: Use MID instruction with starting position 1. CODESYS: Use LEFT() function in ST.
Related Function Blocks
CONCAT (String Concatenation)
Joins two or more strings into a single combined string.
View Reference →RIGHT (Right String Extract)
Extracts a specified number of characters from the end of a string.
View Reference →FIND (String Search)
Finds position of a substring within a string; returns 0 if not found.
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