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 A1:C4 to a blank worksheet.

1
2
3
4
A B C
Formula Result Description
=LEN("Excel") 5 Length of the string.
=LEN("Excel 2013") 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.

Video training

See also: Excel text functions

ASC
Changes full-width (double-byte) English letters or katakana within a character string to half-width (single-byte) characters
BAHTTEXT
Converts a number to text, using the ß (baht) currency format
CHAR
Returns the character specified by the code number
CLEAN
Removes all nonprintable characters from text
CODE
Returns a numeric code for the first character in a text string
CONCATENATE
Joins several text items into one text item
DOLLAR
Converts a number to text, using the $ (dollar) currency format
EXACT
Checks to see if two text values are identical
FIND, FINDB
Finds one text value within another (case-sensitive)
FIXED
Formats a number as text with a fixed number of decimals
WIDECHAR
Changes half-width (single-byte) English letters or katakana within a character string to full-width (double-byte) characters
LEFT, LEFTB
Returns the leftmost characters from a text value
LEN, LENB
Returns the number of characters in a text string
LOWER
Converts text to lowercase
MID, MIDB
Returns a specific number of characters from a text string starting at the position you specify
PHONETIC
Extracts the phonetic (furigana) characters from a text string
PROPER
Capitalizes the first letter in each word of a text value
REPLACE, REPLACEB
Replaces characters within text
REPT
Repeats text a given number of times
RIGHT, RIGHTB
Returns the rightmost characters from a text value
SEARCH, SEARCHB
Finds one text value within another (not case-sensitive)
SUBSTITUTE
Substitutes new text for old text in a text string
T
Converts its arguments to text
TEXT
Formats a number and converts it to text
TRIM
Removes spaces from text
UPPER
Converts text to uppercase
VALUE
Converts a text argument to a number