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'
Free · no signup to try
Run this block in your browser
Try the instruction on a live rung before you copy it into a project — nothing to install.
Try it in your browser — no signupOpens plcsimulationsoftware.com — same team
Prefer ready-made code? Ladder Logic Pack — $29 on Gumroad
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 →Free · no signup to try
Wire this block up and run it
Drop the instruction into a rung, press Run and watch it execute in your browser — then adapt it to your vendor tool.
Try it in your browser — no signupOpens plcsimulationsoftware.com — same team
Prefer ready-made code? Ladder Logic Pack — $29 on Gumroad