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

After


after returns the part of a string that appears after the first occurrence of a separator.


Overview

Use after when a string has a known marker and you want everything that follows it.

log_entry | "ERROR: tunnel collapsed"
message | after(log_entry, ": ")

:say(message)  /// tunnel collapsed
log_entry | "ERROR: tunnel collapsed"
message | after(log_entry, ": ")

:say(message)  /// tunnel collapsed

after removes the separator itself from the result.


First Occurrence

If the separator appears more than once, after uses the first occurrence:

route | "caves/upper/armory"

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

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

To split after the final occurrence instead, use After Last.


Missing Separator

If the separator does not occur in the string, after returns an empty string:

after("tunnel-map", ":")  /// ""
after("tunnel-map", ":")  /// ""

This differs from Before, which returns the original string when its separator is missing.


Signature

after(string, separator)
after(string, separator)

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

after returns a string.


Errors

after requires exactly two arguments:

after("region:north")
/// error: R0301 wrong-arity
after("region:north")
/// error: R0301 wrong-arity

Both arguments must be strings:

after("region:north", 2)
/// error: T0205 type-mismatch
after("region:north", 2)
/// error: T0205 type-mismatch