Skip to main content

LEN, LENB function

Description

LEN function returns the number of characters in a text string.

LENB function returns the number of bytes used to represent the characters in a text string.

What is the difference between LEN and LENB?

LEN is intended for use with languages that use the single-byte character set (SBCS), whereas LENB is intended for use with languages that use the double-byte character set (DBCS). The default language setting on your computer affects the return value in the following way:

  • LEN always counts each character, whether single-byte or double-byte, as 1, no matter what the default language setting is.
  • LENB counts each double-byte character as 2 when you have enabled the editing of a language that supports DBCS and then set it as the default language. Otherwise, LENB counts each character as 1.

The languages that support DBCS include Chinese (Simplified), Chinese (Traditional), Korean, and Japanese.

Syntax

LEN(text)
LENB(text)

Parameters

Text Required. The text whose length you want to find. Spaces count as characters.

Examples

Example 1: LEN

The example may be easier to understand if you copy the example data (include header) in the following table, and paste it in cell A1 of a new Excel worksheet. If you need to, you can adjust the column widths to see all the data.

Formula Result Description
=LEN("Excel") 5 Length of the string.
=LEN("Excel 2019") 10 Length of the string, which includes 1 space.
=LEN("") 0 Length of the string.

Example 2: LENB

=LENB("中国香港")

equals 8. LENB returns 8, because each character is counted as 2.

=LEN("中国香港")

equals 4. LEN returns 4, because each character is counted as 1. LEN returns 4 no matter what the default language setting is on your computer.

Leave a comment

Your email address will not be published. Required fields are marked *

Format your code: <pre><code class="language-vba">place your code here</code></pre>