ddonche/goblin-lang
0.46.24
1
0
docs reference
[[after-last]]

after_last


after_last returns the part of a string after the final occurrence of a separator.


Overview

Use after_last when a separator may appear several times and you only want the text following the final one.

file_path | "maps/caves/entrance.gbln"
filename | after_last(file_path, "/")

:say(filename)  /// entrance.gbln
file_path | "maps/caves/entrance.gbln"
filename | after_last(file_path, "/")

:say(filename)  /// entrance.gbln

The separator itself is not included in the result.


Final Occurrence

after_last searches from the end of the string:

route | "caves/upper/armory"

after_last(route, "/")  /// armory
route | "caves/upper/armory"

after_last(route, "/")  /// armory

Compare this with After, which uses the first occurrence:

after(route, "/")       /// upper/armory
after_last(route, "/")  /// armory
after(route, "/")       /// upper/armory
after_last(route, "/")  /// armory


Missing Separator

If the separator does not appear, after_last returns an empty string:

after_last("entrance.gbln", "/")  /// ""
after_last("entrance.gbln", "/")  /// ""


Signature

after_last(string, separator)
after_last(string, separator)

Argument Type Description
string string The text to search.
separator string The marker whose final occurrence ends the discarded part.

after_last returns a string.


Errors

after_last requires exactly two arguments:

after_last("maps/caves/entrance.gbln")
/// error: R0301 wrong-arity
after_last("maps/caves/entrance.gbln")
/// error: R0301 wrong-arity

Both arguments must be strings:

after_last("maps/caves/entrance.gbln", 2)
/// error: T0205 type-mismatch
after_last("maps/caves/entrance.gbln", 2)
/// error: T0205 type-mismatch