MID
The MID function returns the given number of characters from a string starting from the specified position.
This function can be useful when you need to extract part of the text from a longer string.
Syntax
MID(string, start_num, num_characters)
| Argument | Description | Permitted values |
|---|---|---|
| string | Text string containing the fragment to be extracted | Text string or reference to a cell containing text |
| start_num | Number of the character in the text string from which the extracted fragment begins | Integer ≥1 or a reference to a cell containing a number |
| num_characters | Length of the fragment to be extracted | Integer >0 or a reference to a cell containing a number |
Examples of use
Retrieving a substring
=MID("Hello, world!", 1, 5)
Returns “Hello” because it extracts 5 characters starting from the 1st position.
Extraction using variables
If cell A1 contains the text “Spreadsheet,” you can use:
=MID(A1, 3, 4)
The formula will return “read” starting from the 3rd position and extract 4 characters.
Notes
- If the start_num is greater than the length of the string, the function will return an empty string.
- If the num_characters argument is greater than the number of characters remaining in the string, the function will return all remaining characters.