Text functions
LENB
Matches all 13 recorded answers
Recorded: 13 workbook cells. How we measure this · See the Rust code
Local names in 40 languages
| Language | Name in Excel |
|---|---|
| Arabic | LENB |
| Bulgarian | LENB |
| Czech | LENB |
| Danish | LÆNGDEB |
| German | LENB |
| Greek | LENB |
| English (Australia) | LENB |
| English (United Kingdom) | LENB |
| English (United States) | LENB |
| Spanish | LARGOB |
| Estonian | LENB |
| Finnish | PITUUSB |
| French | LENB |
| Hebrew | LENB |
| Croatian | LENB |
| Hungarian | HOSSZ2 |
| Indonesian | LENB |
| Italian | LENB |
| Japanese | LENB |
| Korean | LENB |
| Lithuanian | LENB |
| Latvian | LENB |
| Norwegian | LENGDEB |
| Dutch | LENGTEB |
| Polish | DŁ.B |
| Portuguese (Brazil) | LENB |
| Portuguese (Portugal) | NÚM.CARATB |
| Romanian | LENB |
| Russian | ДЛИНБ |
| Slovak | LENB |
| Slovenian | LENB |
| Serbian (Latin) | LENB |
| Swedish | LÄNGDB |
| Thai | LENB |
| Turkish | UZUNLUKB işlevleri |
| Ukrainian | LENB |
| Vietnamese | LENB |
| Chinese (Simplified) | LENB |
| Chinese (Hong Kong) | LENB |
| Chinese (Traditional) | LENB |
Names from Microsoft's support site.
What it does
LENB(text)
LENB returns the number of bytes used to represent a text string, where LEN returns the
number of characters. That one substitution — bytes for characters — is the entire difference
between the two functions, and it is why the Handbook publishes them as two entries against
Microsoft's one article. (Seven published rows document a byte-variant pair this way; the
Handbook splits all seven, which is the whole of the difference between 534 published Excel
rows and 541 Handbook entries.)
What "bytes" means here. The byte-variant functions come from the era in which East Asian text was stored in a double-byte character set (DBCS): a host encoding in which some characters occupy one byte and others two. Under such an encoding a string's byte length is not a fixed multiple of its character length — it is one byte per single-byte character plus two per double-byte character — so "how many bytes is this string" and "how many characters is this string" are genuinely different questions with genuinely different answers, and a program working against fixed-width record layouts needs the first one.
The standard consequence follows arithmetically: where every character in the string is
single-byte, LENB and LEN return the same number. The two functions diverge only on text
containing double-byte characters, under a host whose language setting supports DBCS. This
makes LENB an easy function to believe you have tested when you have not — an all-ASCII test
suite cannot tell the two functions apart at all.
What the documentation now says. The Microsoft article that covers this pair states, in one
line, that "the LENB function is deprecated". The text retrieved for this page contains no
statement about DBCS, no list of the languages or language settings under which LENB differs
from LEN, and no definition of the byte count. The Handbook therefore records the
byte-versus-character distinction as the function's stated purpose and historical definition,
and records that the current article does not define it. It does not assert which languages or
code pages are affected, because the article does not say.
The definition has not vanished from Microsoft's documentation altogether: the FIND, FINDB
article still carries the SBCS/DBCS paragraph, including 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 LENB, whose own article no longer says.
Arguments
text — required, the text whose byte length you want. It is the same argument as LEN's,
with the same to-text conversion of numbers and logicals.
There is no encoding argument. The encoding is the host's, which is exactly why this function's
answer is environment-dependent in a way LEN's (mostly) is not.
Try it
Quirks
Result and edge cases
The return kind is Number, a non-negative integer.
- Empty text is 0 under any encoding.
- On single-byte text the result equals
LEN's. That is not a coincidence to be worked around; it is the definition specialising. - The astral-character question that dominates
LEN— surrogate pairs, and the Compatibility Version 2 change to how they are counted — has no documented counterpart here. What a byte count is supposed to mean for a character that the historical DBCS encodings could not represent at all is undefined by any source this page can cite.
Errors
The article enumerates no error conditions. Reachable errors are the shared ones: propagation
of an error argument, and #VALUE! for a value kind with no text conversion
(chapter 02).
How to implement
Notes for implementers
- Do not implement
LENBasLEN. They coincide only on single-byte text. An implementation that aliases them is implementing the non-DBCS specialisation and should say so rather than claim the function. - The byte count needs a named encoding. "Bytes" is meaningless without one. An implementation must state which encoding it measures in and where that encoding comes from (system ANSI code page, workbook setting, or a fixed choice).
- Astral characters need a stated policy for the reason given above: they have no natural DBCS byte length.
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.
LENB · 5 lines · calc-func/src/catalogue/text_functions.rs on GitHub9 lenb_fn "LENB" (1, 1) [V "text"] |s, a, sv| {
single_byte(s)?;
let text = text_arg(s, a, 0)?;
s.number(text.len_utf16_code_units() as f64)
}
Kernels shared with other functions
single_bytecatalogue/text_functions
Argument and result plumbing
text_argcatalogue/kit
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
LENis the character-counting partner and the function to use in new work. Microsoft documents both in one article and marksLENBdeprecated there.LEFTB,RIGHTB,MIDB,FINDB,SEARCHB,REPLACEBare the rest of the byte-variant family. They share the same unit substitution and the same deprecation posture, and an implementation should treat the unit as one shared decision rather than seven. SeeLEFTBandFINDB.ASCandDBCSare the width-conversion functions from the same lineage, converting between full-width and half-width forms.
Named variants
No named variants are recorded yet.
Suggest a correction or contribute an implementation · For agents