Documentation/Calc Functions/MID
TDF LibreOffice Document Liberation Project Community Blogs Weblate Nextcloud Redmine Ask LibreOffice Donate
Function name:
MID
Category:
Text
Summary:
Extracts a sub-string from the middle of the supplied text string, with the start position and length of the sub-string specified in characters.
Syntax:
MID(Text; Start; Number)
Returns:
Returns a text string comprising the specified number of characters from the specified position within the supplied text string.
Arguments:
Text is a text string (in quotation marks), a number, or a reference to a cell containing one of those types, that is the string from which characters are to be extracted.
Start is a positive integer, or a reference to a cell containing a positive integer, that is the position of the first character to be extracted.
Number is a non-negative integer, or a reference to a cell containing a non-negative integer, that is the number of characters to be extracted.
- If either Start or Number is non-numeric, then MID reports a #VALUE! error.
- If either Start or Number is a non-integer value, then MID truncates it to an integer value.
- If after truncation Start is less than 1, then MID reports an invalid argument error (Err:502).
- If after truncation Start is greater than the length (in characters) of Text, then MID returns the empty string.
- If Number is less than 0, then MID reports an invalid argument error (Err:502).
- If after truncation Number is equal to 0, then MID returns the empty string.
- If (Start + Number – 1) is greater than the length (in characters) of Text, then MID returns a string comprising all characters from Start to the end of Text.
Additional details:
Note that =MID(text; 1; length)
is equivalent to =LEFT(text; length)
Examples:
Formula | Description | Returns |
---|---|---|
=MID("Input string"; 2; 3) | Here the function returns three characters from the supplied string, starting at the second character. | npu |
=MID(12,345.6789; 5; 4) | Here the function returns four characters from the supplied number, starting at the fifth character, and formats the result as a text string. | 5.67 |
=MID(D1; D2; D3) where cell D1 contains the string "Input string", cell D2 contains the number 2, and cell D3 contains the number 3. | Here the function returns three characters from the supplied string, starting at the second character. | npu |
=MID("Input string"; 6; 0) | Here the function returns the empty string. |
Related LibreOffice functions:
ODF standard:
Related (or similar) Excel functions:
MID