Text functions
LEFTB
Matches all 5 recorded answers
Recorded: 5 workbook cells. How we measure this · See the Rust code
Local names in 40 languages
| Language | Name in Excel |
|---|---|
| Arabic | LEFTB |
| Bulgarian | LEFTB |
| Czech | LEFTB |
| Danish | VENSTREB |
| German | LEFTB |
| Greek | LEFTB |
| English (Australia) | LEFTB |
| English (United Kingdom) | LEFTB |
| English (United States) | LEFTB |
| Spanish | IZQUIERDAB |
| Estonian | LEFTB |
| Finnish | VASENB |
| French | GAUCHEB |
| Hebrew | LEFTB |
| Croatian | LEFTB |
| Hungarian | BAL2 |
| Indonesian | LEFTB |
| Italian | LEFTB |
| Japanese | LEFTB |
| Korean | LEFTB |
| Lithuanian | LEFTB |
| Latvian | LEFTB |
| Norwegian | LEFTB |
| Dutch | LINKSB |
| Polish | LEWYB |
| Portuguese (Brazil) | LEFTB |
| Portuguese (Portugal) | ESQUERDAB |
| Romanian | LEFTB |
| Russian | ЛЕВБ |
| Slovak | LEFTB |
| Slovenian | LEFTB |
| Serbian (Latin) | LEFTB |
| Swedish | VÄNSTERB |
| Thai | LEFTB |
| Turkish | SOLB işlevleri |
| Ukrainian | LEFTB |
| Vietnamese | LEFTB |
| Chinese (Simplified) | LEFTB |
| Chinese (Hong Kong) | LEFTB |
| Chinese (Traditional) | LEFTB |
Names from Microsoft's support site.
What it does
LEFTB(text, [num_bytes])
LEFTB returns the leading portion of a text string measured in bytes, where
LEFT measures in characters. The unit is the only difference between them,
and it is why the Handbook publishes the pair as two entries against Microsoft's one article.
(Seven published rows document a byte-variant pair this way; splitting all seven is the whole
of the difference between 534 published Excel rows and 541 Handbook entries.)
What "bytes" means here. The byte variants come from the era of double-byte character
sets (DBCS): host encodings in which some characters occupy one byte and others two. Asking
for the first n bytes of such a string is a different question from asking for the first n
characters, because the two counts advance at different rates through the same text. Where
every character in the string is single-byte, the two questions coincide and LEFTB and LEFT
return the same result; they diverge only on text containing double-byte characters, under a
host whose language setting supports DBCS.
LEFTB carries one problem LENB does not: a byte count can land in the middle of a
character. LEFTB(t, 1) applied to a string beginning with a double-byte character asks for
half of that character. Every implementation of a byte-slicing function must have a rule for
that case — return a half character, drop it, or pad — and no source cited on this page states
which rule Excel uses. That is the central unresolved question about this function, and it has
no analogue in the character-counting variant.
What the documentation now says. The Microsoft article that covers the pair states that
"the LEFTB function is deprecated", and adds that LEFT now handles Unicode surrogates through
the Compatibility Version feature (Version 2) — the modern replacement for the problem byte
counting was once used to work around. The text retrieved for this page contains no DBCS
statement, no list of affected languages or language settings, and no definition of the byte
count or of the split-character rule. The Handbook records the byte semantics as the function's
stated purpose and historical definition, and records that the current article does not define
them. It does not assert which locales are affected, because the article does not say.
The definition survives elsewhere in Microsoft's own documentation: the FIND, FINDB article
still carries the SBCS/DBCS paragraph and the condition under which a byte variant counts a
double-byte character as 2. That paragraph is quoted on FINDB, and it is the
best surviving statement of what byte counting means anywhere in this family — including for
LEFTB, whose own article no longer says.
Arguments
text — required, the text string containing the characters to extract.
num_bytes — optional, specifying how many characters to extract in bytes. The
corresponding LEFT argument is documented as defaulting to 1, requiring a value greater than
or equal to zero, and returning the whole text when it exceeds the length; the same shape is
the natural reading here, and this page treats it as the expected behaviour rather than a
documented one, since the retrieved article states those rules for LEFT under the name
num_chars.
Try it
Quirks
Result and edge cases
The return kind is Text.
- On single-byte text the result equals
LEFT's. That is the definition specialising, not a coincidence, and it is why an all-ASCII test suite cannot distinguish the two functions. - A count landing mid-character is the interesting case, and it is undefined by every source this page can cite.
- A count beyond the byte length is expected to yield the whole text, by analogy with
LEFT; unverified. - Astral characters have no natural DBCS byte length at all, so the interaction between
LEFTBand the surrogate handling that the Compatibility Version feature changed is doubly undefined.
Errors
The article enumerates no error conditions for the B variant. Reachable errors are the shared
ones: propagation of an error argument, and #VALUE! for a value kind with no text conversion
(chapter 02). Whether a negative num_bytes errors the
same way a negative num_chars does is unverified.
How to implement
Notes for implementers
- Do not implement
LEFTBasLEFT. They coincide only on single-byte text, and aliasing them is implementing the non-DBCS specialisation. Say so if that is what you are shipping. - Name the encoding. A byte count is meaningless without one, and the historical answer —
the host's system code page — makes this function environment-dependent in a way
LEFTis not. - Write the mid-character rule down, whatever you choose, and test it first; it is the only behaviour a byte-slicer has that a character-slicer does not.
- Guard the text-cap and surrogate interactions. A byte slicer built over UTF-16 storage can produce ill-formed text through two independent mechanisms — surrogate splitting and DBCS splitting — and the value-universe chapter records ill-formed UTF-16 as a reachable state that downstream code must survive.
Rust code
Show the CalcFunc source of this function
Quoted from the public repository DnaCalc/DnaCalc, crates calc-func and calc-fml, at commit 9e1884369a67. Comments are the source's own. A kernel shared with other functions appears once, on its module page.
LEFTB · 1 lines · calc-func/src/catalogue/text_functions.rs on GitHub10 leftb_fn "LEFTB" (1, 2) [V "text", V "num_bytes"] |s, a, sv| { single_byte(s)?; left(s, a) }
Kernels shared with other functions
single_bytecatalogue/text_functionsside_countcatalogue/text_functionsleftcatalogue/text_functionstextported/text_kernelstext_from_strported/text_kernelsdate_integer_floorported/text_kernelsnonnegative_countported/text_kernelsunit_widthported/text_kernelscharacter_boundaryported/text_kernelsslice_character_countported/text_kernelscharacter_scan_endported/text_kernelslen_character_countported/text_kernelstake_leftported/text_kernelstruncatedported/text_kernelspush_singleton_or_originalported/text_kernelspush_upperported/text_kernelsupperported/text_kernels
Argument and result plumbing
No implementation has been published with a Handbook test suite for this function.
Version differences
No comparison between specific Excel builds is recorded here yet. This does not establish that all builds behave alike.
Alternatives
Relationships
LEFTis the character-counting partner, documented in the same article, which marksLEFTBdeprecated.LEFTis the function to use in new work.RIGHTB,MIDB,LENB,FINDB,SEARCHB,REPLACEBare the rest of the byte-variant family. The unit is one shared decision across all seven, and so is the mid-character rule.ASCandDBCSconvert between half-width and full-width forms and are the functions people actually reach for when the problem is character width rather than storage width.
Named variants
No named variants are recorded yet.
Suggest a correction or contribute an implementation · For agents