Check Sheet Logo
Check Sheet

LENB

The LENB function in Google Sheets is used to count the number of bytes in a given text string. This function is useful when working with double-byte character set (DBCS) languages, such as Chinese, Japanese, or Korean, where each character is represented by two bytes. The LENB function returns the number of bytes in a string, which will be twice the number of characters in the string if it contains only DBCS characters.

Usage

Use the LENB formula with the syntax shown below, it has 1 required parameter:

=LENB(string)
Parameters:
  1. string (required):
    The text string for which to count the number of bytes. This can be a cell reference or a text string enclosed in quotation marks.

Examples

Here are a few example use cases that explain how to use the LENB formula in Google Sheets.

Counting bytes in a DBCS string

When working with DBCS languages, the LENB function can be used to accurately count the number of bytes in a string, which is important when working with certain file formats or when sending data to external systems that require byte counts.

Checking for truncation

In some cases, a system or file may have a maximum byte limit for strings. The LENB function can be used to check if a string will be truncated before sending it to the external system or saving it to a file.

Validation of DBCS input

When building forms or other input fields that accept DBCS text, the LENB function can be used to validate that the input does not exceed a certain number of bytes.

Common Mistakes

LENB not working? Here are some common mistakes people make when using the LENB Google Sheets Formula:

Using LENB with single-byte character sets

If you're working with a single-byte character set such as ASCII, LENB will return the same result as LEN, causing your calculations to be incorrect.

Using LENB instead of LEN

If you're working with a single-byte character set such as ASCII, it's important to use LEN instead of LENB to count the number of characters in a text string, otherwise your calculations will be incorrect.

The following functions are similar to LENB or are often used with it in a formula:

  • LEN

    The LEN formula in Google Sheets is used to count the number of characters in a given text string. It is commonly used to check the length of text inputs, or to find the length of a cell value or range.

  • LEFTB

    The LEFTB formula is used to extract a specified number of bytes from the beginning of a text string. This formula is similar to the LEFT formula, but instead of counting characters, it counts bytes. This can be useful when working with languages that use multi-byte characters, such as Chinese or Japanese.

  • RIGHTB

    The RIGHTB function returns a specified number of bytes from the end of a text string. This function is useful when working with non-Latin languages, where a character may be represented by multiple bytes. It is commonly used to extract file extensions or to truncate text to a certain length. The function is case-sensitive.

Learn More

You can learn more about the LENB Google Sheets function on Google Support.