Leftb
Syntax:¶
LEFTB(text, [num_bytes])
- text: The text string from which you want to extract characters. This can be a direct string, a cell reference, or the result of another function.
- num_bytes (optional): The number of bytes to extract starting from the left side of the string. If omitted, it defaults to 1.
Description:¶
The LEFTB function in Excel returns the first character or characters in a text string, based on the number of bytes
you specify rather than the number of characters. This distinction is important when working with double-byte character
set (DBCS) languages such as Japanese, Chinese, and Korean, where a single character can occupy two bytes. In single-byte
character set (SBCS) languages such as English, LEFTB behaves identically to the LEFT function because each
character is one byte.
Examples:¶
=LEFTB("Excel", 2)- Returns:
"Ex"(In an SBCS environment, the first 2 bytes correspond to the first 2 characters.)
- Returns:
=LEFTB("Excel")- Returns:
"E"(Whennum_bytesis omitted, it defaults to 1, returning the first byte.)
- Returns:
=LEFTB(A1, 4)- Returns the first 4 bytes of text from cell A1.
(In an SBCS environment, this is equivalent to
=LEFT(A1, 4).)
- Returns the first 4 bytes of text from cell A1.
(In an SBCS environment, this is equivalent to
=LEFTB("Excel", 10)- Returns:
"Excel"(Ifnum_bytesexceeds the byte length of the text, the entire string is returned.)
- Returns:
Notes:¶
- In SBCS languages (e.g., English),
LEFTBreturns the same results asLEFTbecause each character equals one byte. The difference only becomes apparent in DBCS languages where characters may occupy two bytes. - If
num_bytesis greater than the byte length of the text string, theLEFTBfunction will return the entire string without any error. - If
num_bytesis set to 0, the result will be an empty string (""). - If
num_bytesis negative, Excel will return a#VALUE!error. - The
num_bytesargument counts bytes, not characters. When working with DBCS text, be mindful that a double-byte character occupies positions for two bytes. - For character-based extraction from the left (rather than byte-based), use the
LEFTfunction. - The
LEFTBfunction is equivalent toLEFTin Excel when the default language setting is a single-byte character set language. In DBCS language environments,LEFTBcounts each double-byte character as 2 bytes.