Documentation/Calc Functions/MIDB

Function name:
MIDB

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 bytes.

Syntax:
MIDB(Text; Start; Number of Bytes)

Returns:
Returns a text string comprising the specified number of bytes 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 byte to be extracted.

Number of Bytes is a non-negative integer, or a reference to a cell containing a non-negative integer, that is the number of bytes to be extracted.


 * If either Start or Number of Bytes is non-numeric, then MIDB reports a #VALUE! error.
 * If either Start or Number of Bytes is a non-integer value, then MIDB truncates it to an integer value.
 * If after truncation Start is less than 1, then MIDB reports an invalid argument error (Err:502).
 * If after truncation Start is greater than the length (in bytes) of Text, then MIDB returns the empty string.
 * If Number of Bytes is less than 0, then MIDB reports an invalid argument error (Err:502).
 * If after truncation Number of Bytes is equal to 0, then MIDB returns the empty string.
 * If (Start + Number of Bytes – 1) is greater than the length (in bytes) of Text, then MIDB returns a string comprising all bytes from Start to the end of Text.

Details specific to MIDB function
If the specified number of bytes would otherwise lead to extracting only one byte of a two-byte character, MIDB instead inserts a space character (Unicode U+0020) at the end of the returned string.

Note that  is equivalent to

Examples:
The following examples are similar to those used for the MID function and demonstrate the consistent behavior of the two functions for single-byte character strings.

The remaining examples demonstrate the behavior of MIDB for strings that include double-byte characters. These examples utilize the double-byte characters "中" (Unicode CJK Unified Ideograph-4E2D) and "国" (CJK Unified Ideograph-56FD).

Related LibreOffice functions:
FINDB

LEFTB

LENB

MID

REPLACEB

RIGHTB

SEARCHB

ODF standard:
Section 6.7.5, part 2

Equivalent Excel functions:
MIDB