MIDB Function (LibreOffice Calc)
Extract byte-counted substrings with LibreOffice MIDB. Understand one-based starts, zero lengths and the spaces inserted when a boundary splits a two-unit character.
Verification status: Eight ordinary formula examples were recalculated in LibreOfficeDev 26.8.0.0.alpha0 (2c87e51eeaa2b413ff4ae097b2705eea1995d8e5) using headless XLSX import and forced recalculation. Exact saved text/positions and both controls were checked. LibreOffice 26.8.1.1 was source-checked only; no stable-release or GUI execution is claimed. How formula examples are checked
Quick answer: =MIDB("ä¸å›½";1;1) returned " “ in the tested development build.
Availability and version history
- Introduced: Introduced in LibreOffice 4.2.
- Supported in: LibreOffice 26.8 Help and 26.8.1.1 registration; no retirement is established.
- Scope: Desktop Calc, English semicolon-separated formulas. The byte convention is not a file-encoding byte offset.
- Checked: October 14, 2026. Eight listed formulas were recalculated in LibreOfficeDev 26.8.0.0.alpha0 using headless XLSX import. Stable releases and 26.8.1.1 were not executed.
What MIDB returns
MIDB extracts a span using Calc’s byte-counting convention. In these examples each Chinese character occupies two units and each ASCII character occupies one. If a requested edge cuts through a two-unit character, the helper supplies a space for the incomplete part instead of returning a broken character. Function Help.
Syntax and arguments
MIDB(Text; Start; NumberBytes)
Text is the string to inspect. Start is a one-based byte position. NumberBytes is the requested span length. All three arguments are required. The inspected guard requires Start at least 1 and a nonnegative length; both numbers are read through the shared string-position conversion helper.
Eight reproducible examples
The native column is from LibreOfficeDev 26.8.0.0.alpha0, build 2c87e51eeaa2b413ff4ae097b2705eea1995d8e5, using headless XLSX import and forced recalculation. Text is quoted to distinguish empty strings and spaces. Delimiting quotation marks are not returned characters.
| Formula | Independent reference | LibreOfficeDev result |
|---|---|---|
=MIDB("ä¸å›½";1;1) |
" " |
" " |
=MIDB("ä¸å›½";1;2) |
"ä¸" |
"ä¸" |
=MIDB("ä¸å›½";1;3) |
"ä¸ " |
"ä¸ " |
=MIDB("ä¸å›½";2;2) |
" " |
" " |
=MIDB("ä¸å›½";2;3) |
" 国" |
" 国" |
=MIDB("Aä¸å›½B";2;4) |
"ä¸å›½" |
"ä¸å›½" |
=MIDB("office";2;3) |
"ffi" |
"ffi" |
=MIDB("ä¸å›½";1;0) |
"" |
"" |
Practical worksheet
For ä¸å›½, ä¸ occupies positions 1–2 and 国 occupies 3–4. Starting at 1 with length 2 returns ä¸. Length 3 returns ä¸ followed by one ordinary space because only half of 国 is included.
Starting at position 2 with length 2 cuts the second half of ä¸ and the first half of 国. The returned string contains two spaces. The table represents it as " “; keep both spaces when reproducing the result. A browser or a casual visual inspection can make that different from a one-space string.
For a mixed field Aä¸å›½B, MIDB with start 2 and length 4 returns ä¸å›½. The ordinary MID function uses character positions instead, so replacing one function with the other can change the extracted field even when the same numbers are supplied.
Advanced interpretation and checks
The implementation first takes a byte-aware left prefix ending at Start+NumberBytes−1. It then takes the required right portion of that prefix. Both helper operations preserve complete characters and substitute spaces when an edge splits a two-unit character.
This two-stage construction explains the two-space example: the first operation creates a trailing space for the split 国, and the second creates a leading space for the split ä¸. Those spaces are actual output characters, not padding added by a cell format.
A length of zero returns empty text in the listed example. The ASCII example MIDB(“office”;2;3) returns ffi because the selected letters each count as one unit. These simple checks help distinguish a zero-length extraction from a space-containing extraction.
The unit is a spreadsheet compatibility convention. It is not a count of UTF-8 octets and should not be used to slice an encoded file. The inspected helper classifies Unicode blocks and also has a Japanese-system-language special case for backslash and euro sign; the current examples avoid that locale-dependent pair. Inspected implementation.
Boundaries and troubleshooting
A start below 1 or a negative count follows an illegal-argument branch in the inspected source. Requests beyond the text are handled by the prefix/suffix helpers, but no broad large-index or overflow behavior is established by the ordinary cases here.
Use LENB to reason in the same counting convention and LEN when you mean character length. A returned string containing one or two spaces can be a valid split-boundary result rather than an unexpected blank cell.
The official Help’s prose describes two spaces for MIDB(“ä¸å›½”;2;2); rendered whitespace can make the shown result look shorter. The exact string representation and independent reconstruction in this guide preserve the two separate spaces.
Related functions
Official evidence and checking scope
- Function-specific Help
- Complete versioned callback
- English native-name registration
- Byte classification and left/right helpers
The exact saved formulas and text were reconciled, including ODF repeated-space elements. Three empty-text cases across the fixture retain their formulas and empty paragraphs without a serialized value-type attribute; they are recorded as empty formula results. The stale SUM cache refreshed to 3 and the uncached SUM returned 7. This is headless development-build evidence, not a stable-release or GUI test.