LEFTB
The LEFTB function returns a specific number of characters from the beginning of a string, based on the given amount of bytes.
This function is useful when working with texts containing characters that are larger than one byte, for example, in languages with multi-byte characters (such as Chinese, Japanese, and Korean).
Syntax
LEFTB(string, [num_bytes])
| Argument | Description | Permitted values |
|---|---|---|
| string | String from which the left fragment will be returned | Text string or reference to a cell containing text |
| [num_bytes] | (optional) The number of bytes that need to be returned from the left side of the “string” argument. By default, 1 | Positive integer or a reference to a cell with a number |
Examples of use
Retrieving the first 5 bytes from a string:
=LEFTB("Hello, world!", 5)
If the string consists of characters, each of which occupies 1 byte, the formula will return “Hello”.
However, if the string contains multibyte characters, the result may be different.
If the number of bytes is not specified, the function will return 1 byte:
=LEFTB("Test")
This formula will return T.
Notes
- If the value of the num_bytes argument exceeds the length of the string, the function will return the entire string.
- If the string contains characters that occupy more than one byte, make sure you specify the number of bytes correctly to avoid errors.