LEFTB

    Text

    Returns the leftmost characters of a text string based on a number of bytes. Each double-byte character (DBCS) counts as 2 bytes; single-byte characters count as 1.

    Translations
    EnglishLEFTB
    FrenchGAUCHEB
    SpanishIZQUIERDAB
    GermanLINKSB
    ItalianSINISTRAB
    PortugueseESQUERDAB
    DutchLINKSB
    PolishLEWYB
    RussianЛЕВСИМВБ
    TurkishSOLDANB
    CzechZLEVAB
    HungarianBALB
    SwedishVÄNSTERB
    DanishVENSTREB
    FinnishVASEN.B
    Syntax
    LEFTB(text, [num_bytes])

    Arguments

    • textThe text from which to extract the leftmost characters.
    • num_bytesThe number of bytes to extract (default 1). Must be ≥ 0.(optional)
    Examples
    =LEFTB("Excel",3)
    Exc

    Returns the first 3 bytes

    =LEFTB("日本語",2)

    1 double-byte character = 2 bytes

    =LEFTB("AB日本",4)
    AB日

    2 single-byte + 1 double-byte = 4 bytes

    Tips & Best Practices
    • On systems without DBCS support, LEFTB behaves like LEFT
    • Use LEFT to extract by character count instead of byte count
    • Mainly used in East Asian Excel installations
    • Useful when truncating to byte-based field length limits
    Common Mistakes
    • Using LEFTB when LEFT (character-based extraction) is actually what's needed - LEFTB counts bytes, so a num_bytes value that seems right by character count can cut a double-byte character in half
    • Assuming num_bytes always corresponds directly to a whole number of characters - with double-byte text, an odd num_bytes value can split a single character, producing a garbled or unexpected result
    • Forgetting that on systems without double-byte character set support, LEFTB simply behaves like LEFT, so testing on a Western-locale machine can hide bugs that only appear with East Asian text
    Related Functions
    LEFTExtracts by character count instead of byte count, the correct choice for text that doesn't need double-byte-aware handling.
    RIGHTBPerforms the same byte-based extraction as LEFTB but from the end of the string instead of the beginning.
    MIDBExtracts from any starting byte position, a more flexible version of the same byte-counting logic LEFTB uses.
    Frequently Asked Questions

    Why did LEFTB cut off part of a character instead of a clean substring?

    num_bytes probably fell in the middle of a double-byte character - since each such character occupies 2 bytes, an odd byte count can split one in half, producing a garbled result.

    Should I use LEFT or LEFTB?

    Use LEFT for ordinary character-based extraction. Reach for LEFTB only when you specifically need byte-based counting, such as matching a legacy system's storage limits for East Asian text.

    Does LEFTB work the same as LEFT on a system without double-byte language support?

    Yes, in that case there's no distinction between characters and bytes, so LEFTB and LEFT return identical results.

    Need to translate a formula using LEFTB?

    Use our translator to convert your complete formula