Scan a raw-material label and you often get one string that carries two values: the lot number and the material number, joined by a delimiter as in 48215_90834. Excel cuts that in seconds; a code reader, PLC or HMI needs the same cut done deliberately so each value lands in its own data location. This guide gives controls engineers the decision first (where the split should live), the find-and-cut rule with the arithmetic, a worked 11-character example, and the steps and test strings that prove the split before go-live.
What you need
- Three sample labels: the shortest, the longest and one typical. Scan each and record the raw string, its length and the delimiter position.
- The label specification: which field comes first, what the delimiter is, and whether either field can contain that character.
- The receive path on the host side, because the transport shapes the code. How the scanner connects to a PLC: serial, USB and Ethernet covers each option.
- If you split in the reader: access to its configuration utility and its output-format stage.
Where the split lives: reader parser, PC or PLC
The split is one operation, and it can run in three places. The consumers decide which:
| Split location | The rule lives in | Choose it when | Trade-off |
|---|---|---|---|
| Reader output parser | The reader's configuration utility | Two or more hosts want the fields, or the hosts lack string instructions | Not every reader's parser accepts a custom separator character |
| PC or middleware | A script or regex on the receive path | Fields feed a database or MES, and you also log the raw string | One more program to keep running |
| PLC or HMI | String instructions beside the data locations | One machine, one controller, no PC in the loop | Runs on the controller's scan; string length limits apply |
For one line logging raw material, the controller wins: the fields are written the same scan the string arrives, and nothing else has to stay alive. If your controller ships a dedicated unpack-string instruction, it performs this find-and-cut in a single instruction with the same inputs. For a network reader, settle the connection direction first with the TCP client or listener guide, then budget the link as in the reader-to-PLC communication plan.
The find-and-cut rule
One delimiter, one search, two substrings. For a decoded string S of length n with the delimiter at position p:
Find p at read time; never assume it. Any character that cannot occur in either field works: an underscore is safe for numeric lot and material numbers, and if you print your own labels the GS1 field separator (ASCII 29, the Group Separator) exists for exactly this machine splitting. Where the host speaks regex, the same rule is one pattern with two capture groups: ^(?<lot>[^_]+)_(?<mat>[^_]+)$. The capture-group guide for scanner strings walks that style on decodes, and the pattern that parses raw message fields with regex transfers to scan strings unchanged.
Worked example: splitting the 11-character string 48215_90834 at the underscore
Inputs, from the label format and the planned transport:
- S = 48215_90834, so n = 11 characters; lot number first, underscore, material number, both numeric
- delimiter: underscore, position p found by search
- RS232 serial at 9,600 bit/s, 8N1 framing, message = data + carriage return
Rule: field 1 is everything before the delimiter; field 2 is everything after it, with length n − p.
Arithmetic:
- p = FIND(S, _) = 6: characters 4, 8, 2, 1, 5 occupy positions 1 to 5 and the underscore sits at position 6
- lot = LEFT(S, p − 1) = LEFT(S, 5) = 48215
- material length = n − p = 11 − 6 = 5, so material = MID(S, 7, 5) = 90834
- delivery time: 11 data characters + 1 CR = 12 bytes; 8N1 sends 10 bits per byte, so 12 × 10 = 120 bits; 120 ÷ 9,600 bit/s = 0.0125 s = 12.5 ms per scan message
Result: the values 48215 and 90834 land in their data locations within one controller scan of the string arriving; the serial line, not the split, sets the 12.5 ms.
Decision: fixed offsets LEFT(S, 5) and MID(S, 7, 5) are safe only while every label is exactly 11 characters with the underscore at position 6. One longer lot number breaks them: 482156_90834 has n = 12 and the underscore at position 7, so MID(S, 7, 5) returns _9083 and both fields come out corrupt. Searching p at read time handles both layouts: for the 12-character string, p = 7, lot = LEFT(S, 6) = 482156 and material = MID(S, 8, 5) = 90834. Fix the offsets only when a week of collected labels proves the format constant; otherwise search.
Steps to put the split in place
- Collect three labels — shortest, longest, and one typical — and scan each. Record the raw string, its length n and the delimiter position p for every one.
- Confirm with whoever owns the label that neither field can contain the delimiter. Numeric lot and material numbers cannot produce an underscore.
- Pick the split location from the table above: reader parser for multi-host setups, host string instructions for a single machine.
- Reader path: open the reader's output-format (data parsing) stage in its configuration utility, define the underscore as the field separator, and point the two fields at their destinations. If the parser cannot express a custom separator, keep the raw string and split in the host.
- Host path: on each receive event, strip any prefix and suffix framing first, as in the preamble and serial framing guide, then run the find-and-cut formula and write the two results to their data locations. Behind an HMI input field, script the same cut as shown in the keyboard-wedge scripting method; if the fields also feed a lot-number label printer straight from the PLC, write them to the printer interface's handshake registers the same scan.
- Add the guard: if the delimiter search fails or n is smaller than both fields plus the delimiter, flag the scan bad and skip the write.
- Log the raw string next to the two fields with a timestamp, so a format change months from now can be re-split offline.
- Run the four test strings in the next section and compare every output field against the table.
Test strings that prove it works
| Input string | n | p | Lot field | Material field |
|---|---|---|---|---|
| 48215_90834 | 11 | 6 | 48215 | 90834 |
| 482156_90834 | 12 | 7 | 482156 | 90834 |
| 4821590834 | 10 | not found | scan rejected | scan rejected |
| empty decode or NACK | 0 | — | no write | no write |
Pass all four cases before go-live. The third row is the guard firing; the fourth confirms a failed decode never overwrites good data.
Common mistakes
- Hard-coding character offsets. One changed field length corrupts both fields with no error, exactly as the worked example shows.
- Choosing a delimiter the data can contain, such as a hyphen in material codes like RM-4482. Ask for the field alphabets before you commit.
- Splitting before the framing is stripped, so the search hits a preamble character. Order is strip, then find, then cut.
- Writing fields on every string without a decode-OK check, which stores junk from marginal reads; the read confidence criteria tell you which decodes to trust.
- Letting an HMI tag keep the previous lot through a failed scan. Initialise the tags so a null value is handled, per the null previousValue fix, and clear the pair when a new scan event starts.
Readers that hand the host a clean string
The split only ever sees what the reader sends, so pick a reader whose output matches the host's transport. At a bench or line-side station, a handheld code reader feeds the PC application over USB as in the USB capture guide, or pushes the string over the network:
- Interface
- USB
- Connection
- Wired
- Interface
- Fast Ethernet
- Connection
- Wired
- Interface
- Fast Ethernet
- Connection
- Wired
Of the three, the USB model delivers decodes over a wired USB link; the other two send them over Fast Ethernet, and the PoE variant carries power and data on the same cable, so a wall or pillar mount needs no separate supply.
Pinned above a conveyor, a fixed code reader watches each label pass. Close-up, hand-presented labels suit the LS-CRD-0047: 1.2 MP over USB 2.0 with a 60–120 mm reading distance.
- Resolution
- Up to 3 MP
- Shutter
- Global
- Interface
- USB
For smaller modules or multi-code frames, the MV-ID3013PM-12M-WBN pairs a 1.3 MP sensor with a 12 mm lens on Fast Ethernet, and the LS-CRD-0028 decodes up to 60 codes per second from 2560 x 2048 frames at 30 fps with its 8 mm lens.
- Interface
- Fast Ethernet
- Resolution
- Up to 3 MP
- Shutter
- Global
- Lens mount
- M12
- Interface
- Fast Ethernet
- Resolution
- 5 MP
- Sensor format
- 1/1.7"
- Shutter
- Global
Where to go next
Once lot and material are separate, GTIN product lookup after barcode scanning turns a material number into part data, and the code-to-part verification guide shows how to compare the scanned code against a similar assembly. Size the optics in the camera finder, plan the whole chain in the system configurator, or contact the applications team with your label format and host. More decode-handling work lives on the code-reading topic page.
Questions
Where should the split live: in the reader, the PC or the PLC?
Split in the reader's output parser when more than one host consumes the scan, because each host then receives ready-made fields. Split in the host when you need the raw string logged unchanged, when the reader's parser cannot express a custom separator, or when the fields feed machine data with no PC in the loop. One machine with one controller is the common case: split there, next to the data locations.
What delimiter should I use when I can choose the label format?
Pick a character neither field can contain. For numeric lot and material numbers an underscore is safe. If you print your own labels, the GS1 field separator, ASCII 29 (Group Separator), is purpose-made: a control character that never appears in readable data, so the delimiter search can never land inside a field.
How do I handle lot numbers of different lengths?
Never cut at fixed character positions. Search for the delimiter at read time and compute the second field's length as the total length minus the delimiter position, as in the worked example. Then run the shortest and longest label the printer can emit through the test strings; both must split correctly before go-live.
Can I do the split in Excel?
Excel's Text to Columns performs the same find-and-cut and is fine for analysing logged scans offline. It cannot sit in a scan-to-machine loop: a spreadsheet on the line adds file locks and refresh delay between the scan and the data location. Split on the line in the reader parser or the controller, and keep Excel for the exported log.
What should the host do when a scan has no delimiter?
Treat it as a bad scan. A string with no delimiter is a partial decode, a wrong symbology or a truncated serial message. The guard should flag the event and skip the write rather than store a half string, and the raw input should reach the log so you can tell a reader fault from a transport fault.





