TEXTAFTER (Text, Delimiter, Which?, FallbackValue?) TEXTAFTER (Text; Delimiter; Which?; FallbackValue?)

Text

Text Text

The text string to look in.

Delimiter

Text Text

The delimiter marking the end of the text to return.

Which

Number Number (optional)

A number which specifies which occurrence of the delimiter to use, counting from the left. A negative number counts from the right, meaning that -1 denotes the last occurrence. If omitted, the first occurrence is used. Zero is not a valid value.

FallbackValue

Text Text (optional)

The value to return if the delimiter cannot be found as many times as the Which parameter requires. If omitted, an #N/A error is used.

Returns

Text Text

The text which follows the delimiter.

Returns the text which follows a delimiter in a text string. TEXTAFTER ("first-second", "-") TEXTAFTER ("first-second"; "-") returns "second", the text which follows the first occurrence of the delimiter "-".

Use the third parameter to pick another occurrence of the delimiter. A negative number counts from the right, meaning that TEXTAFTER ("Ada Maria Lovelace", " ", - 1) TEXTAFTER ("Ada Maria Lovelace"; " "; - 1) returns "Lovelace", the last name. Counting from the right is often what you want, as the text you are looking for tends to follow the last delimiter.

Handling text strings without the delimiter

If the delimiter does not appear in the text string — or appears fewer times than the third parameter requires — an #N/A error is returned. Give the fourth parameter to return a value of your choosing instead:

TEXTAFTER ("no delimiter here", "-", 1, "not found")
TEXTAFTER ("no delimiter here"; "-"; 1; "not found")

This formula returns "not found" instead of an error.

Matching is case-sensitive

The delimiter must match exactly, including its case. Use the LOWER or UPPER functions to match regardless of case, by converting both the text string and the delimiter to the same case.

Use TEXTSPLIT to get every part of a text string instead of the text on one side of a delimiter. Use REGEXEXTRACT when the text to find is better described by a regular expression than by a literal delimiter. Use TEXTBEFORE to get the text which precedes the delimiter.

Examples

TEXTAFTER ("first-second", "-")
TEXTAFTER ("first-second"; "-")

Returns "second".

TEXTAFTER ("a-b-c", "-", 2)
TEXTAFTER ("a-b-c"; "-"; 2)

Returns "c", as the text following the second occurrence of "-" is returned.

TEXTAFTER ("Ada Maria Lovelace", " ", - 1)
TEXTAFTER ("Ada Maria Lovelace"; " "; - 1)

Returns "Lovelace", the last name. The Which parameter is -1, meaning that the last occurrence of " " is used.

TEXTAFTER ("david@example.com", "@")
TEXTAFTER ("david@example.com"; "@")

Returns "example.com", the domain name of the email address.

TEXTAFTER ("abc", "-", 1, "not found")
TEXTAFTER ("abc"; "-"; 1; "not found")

Returns "not found", as the delimiter "-" does not appear in the text string and a fallback value is given.

TEXTAFTER ("abc-", "-")
TEXTAFTER ("abc-"; "-")

Returns an empty text string, as no text follows the delimiter.

fxEngine Shell Want this in your own terminal? A standalone version is coming. Get notified.
Loading fxEngine Shell