The LEFT function returns the given number of characters from the beginning of a string.
This function is useful when you need to retrieve a specific number of characters from a text value.
Syntax
LEFT(string, [num_characters])
Argument |
Description |
Permitted values |
|---|---|---|
string |
Text from which the left fragment is returned |
Text string or reference to a cell containing text |
[num_characters] |
(optional) Number of characters to return from the left side of the string. By default, 1 |
Positive integer or a reference to a cell with a number |
Examples of use
Retrieving the first 5 characters from a string:
=LEFT("Hello, world!", 5)
This formula will return "Hello".
If the number of characters is not specified, the function will return 1 character by default:
=LEFT("Test")
This formula will return T.
If the number of characters exceeds the length of the string, the function will return the entire string:
=LEFT("Code", 20)
This formula will return "Code".
Notes
–The LEFT function takes into account all characters, including spaces and special characters.
–If the num_characters argument is less than or equal to 0, the function will return an empty string.