SUBSTRING / MID

Returns the specified number of characters from a string, starting at the specified start position.

Syntax

=SUBSTRING(string, start, count)

=MID(string, start, count)

Arguments

ArgumentTypeDescription
stringStringThe string to get characters from
startNumberThe starting index in the string
countNumberThe number of characters to return

📘

Index is 1-based (i.e. an index of 1 is used for the first character). Negative indexes are allowed and index from the end of the string (i.e. an index of -1 gets the last character).

Examples

=SUBSTRING("ABC", 1, 1)"A"
Gets 1 character from the string "ABC", starting at index 1 ("A")

=SUBSTRING("DEF", 2, 2)"EF"
Gets 2 characters from the string "DEF", starting at index 2 ("E")

=MID("ABCDEF", 3, 0)""
Gets 0 characters from the string "ABCDEF", starting at index 3 ("C")

=SUBSTRING("GHIJKL", -3, 3)"JKL"
Gets 3 characters from the string "GHIJKL", starting at index -3 (3 characters from the end of the string, starting at "J")

=SUBSTRING("GHIJKL", 0, 3)#ERROR!
Gets 3 characters from the string "GHIJKL", starting at index 0 (0 is not a valid index)

=MID("GHIJKL", 10, 1)#ERROR!
Gets 1 character from the string "GHIJKL", starting at index 10 (an invalid index because it is longer than the string)

=SUBSTRING("GHIJKL", -10, 1)#ERROR!
Gets 1 character from the string "GHIJKL", starting at index -10 (an invalid index because it is longer than the string)