Documentation/Calc Functions/LEFTB

    From The Document Foundation Wiki
    Other languages:

    Function name:





    Extracts a sub-string from the left of the supplied text string, with the length of the sub-string specified in bytes.


    LEFTB(Text[; Number of Bytes])


    Returns a text string comprising the specified number of bytes from the left side of the supplied text string.


    Text is a text string (in quotation marks), a number, or a reference to a cell containing one of those types, that is the string from which characters are to be extracted.

    Number of Bytes is a non-negative integer, or a reference to a cell containing a non-negative integer, that is the number of bytes to be extracted. If Number of Bytes is omitted, LEFTB uses the value 1.

    • If Number of Bytes is non-numeric, then LEFTB reports a #VALUE! error.
    • If Number of Bytes is a non-integer value, LEFTB truncates it to an integer value.
    • If Number of Bytes is less than 0, then LEFTB reports an invalid argument error (Err:502).
    • If Text comprises fewer bytes than the value of Number of Bytes, LEFTB returns a copy of Text.

    Additional details:

    Details specific to LEFTB function

    If the specified number of bytes would otherwise lead to extracting only one byte of a two-byte character, LEFTB instead inserts a space character (Unicode U+0020) at the end of the returned string.

    General information about byte-position functions

    Note pin.svg

    For convenience, the information in this subsection is repeated on all pages describing Calc’s byte-position functions.

    Calc provides several byte-position text functions, which are intended to be used with double-byte character set (DBCS) languages. These functions are FINDB, LEFTB, LENB,MIDB, REPLACEB, RIGHTB, and SEARCHB. Each has an equivalent "ordinary" text function with a similar name but without the final letter "B".

    Calc considers double-byte characters to be those characters lying within the following Unicode code blocks:

    • Bopomofo Extended (U+31A0 ... U+31BF)
    • Bopomofo (U+3100 ... U+312F)
    • CJK Compatibility Forms (U+FE30 ... U+FE4F)
    • CJK Compatibility Ideographs Supplement (U+2F800 ... U+2FA1F)
    • CJK Compatibility Ideographs (U+F900 ... U+FAFF)
    • CJK Compatibility (U+3300 ... U+33FF)
    • CJK Radicals Supplement (U+2E80 ... U+2EFF)
    • CJK Strokes (U+31C0 ... U+31EF)
    • CJK Symbols and Punctuation (U+3000 ... U+303F)
    • CJK Unified Ideographs Extension A (U+3400 ... U+4DBF)
    • CJK Unified Ideographs Extension B (U+20000 ... U+2A6DF)
    • CJK Unified Ideographs (U+4E00 ... U+9FFF)
    • Enclosed CJK Letters and Months (U+3200 ... U+32FF)
    • Halfwidth and Fullwidth Forms (U+FF00 ... U+FFEF)
    • Hangul Compatibility Jamo (U+3130 ... U+318F)
    • Hangul Jamo (U+1100 ... U+11FF)
    • Hangul Syllables (U+AC00 ... U+D7AF)
    • High Private Use Surrogates (U+DB80 ... U+DBFF)
    • High Surrogates (U+D800 ... U+DB7F)
    • Hiragana (U+3040 ... U+309F)
    • Ideographic Description Characters (U+2FF0 ... U+2FFF)
    • Kanbun (U+3190 ... U+319F)
    • Kangxi Radicals (U+2F00 ... U+2FDF)
    • Katakana (U+30A0 ... U+30FF)
    • Low Surrogates (U+DC00 ... U+DFFF)
    • Private Use Area (U+E000 ... U+F8FF)
    • Yi Radicals (U+A490 ... U+A4CF)
    • Yi Syllables (U+A000 ... U+A48F)

    See Wikipedia's Unicode block page for more information about these blocks.

    In addition, code points U+005C and U+20AC are taken to be double-byte characters if the system language is set to Japanese.

    As noted in ODF 1.2, byte positions are implementation-dependent and so reliance upon them reduces interoperability.


    The following examples are similar to those used for the LEFT function and demonstrate the consistent behavior of the two functions for single-byte character strings.

    Formula Description Returns
    =LEFTB("Input string"; 2) Here the function returns the first two characters of the supplied string. In
    =LEFTB(12,345.6789; 5) Here the function returns the first five digits of the supplied number, formatted as a text string. 12345
    =LEFTB(D1; D2) where cell D1 contains the string "Input string" and cell D2 contains the number 3. Here the function returns the first three characters of the supplied string. Inp
    =LEFTB("Input string") Here the function returns the first character of the supplied string. The default value of 1 is applied when the Number argument is omitted. I
    =LEFTB("Input string"; 0) Here the function returns the empty string.

    The remaining examples demonstrate the behavior of LEFTB for strings that include double-byte characters. These examples utilize the double-byte characters "中" (Unicode CJK Unified Ideograph-4E2D) and "国" (CJK Unified Ideograph-56FD).

    Formula Description Returns
    =LEFTB("中国"; 1) Here one byte is only half of a double-byte character and so a space character is returned instead. " "
    =LEFTB("中国"; 2) Here the function returns the first character of the string, since one double-byte character occupies two bytes. "中"
    =LEFTB("中国"; 3) Here three bytes constitute one double-byte character and a further byte. The function returns the first character of the string followed by a space character. "中 "
    =LEFTB("中国"; 4) Here the function returns both characters of the string, since two double-byte characters occupy four bytes. "中国"

    Related LibreOffice functions:








    ODF standard:

    Section 6.7.3, part 2

    Related (or similar) Excel functions: