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.
- How to use
- Examples of using
LENBformula not working?
- Similar formulas to
LENB formula with the syntax shown below, it has 1 required parameter:
- 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.
ExamplesHere 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.
LENB not working? Here are some common mistakes people make when using the
LENB Google Sheets Formula:
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.
LENB instead of
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:
LENformula 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.
LEFTBformula is used to extract a specified number of bytes from the beginning of a text string. This formula is similar to the
LEFTformula, 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.
RIGHTBfunction 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.
You can learn more about the
LENB Google Sheets function on Google Support.