after_last
Builtin index · Collections & strings
result = after_last(s, mark)
Input: s, mark · Output: result
What it is
s/mark are Strs.
Overloads
One call shape — this function is not overloaded.
| Code | Input | Output | Description |
result = after_last(s, mark) | s Strnot documented yetmark Strnot documented yet | result Str | Returns a Str: like after/before but searching from the end — the pair to reach for on a path or a dotted name. |
Examples
From the documentation, and run by the build -- the output and the figure below are what the engine actually produced. Simplest first.
path = "report_final_v2.txt"
print(ends_with(path, ".txt")) # true
print(index_of(path, "_")) # 6
print(last_index_of(path, "_")) # 12
print(insert("helloworld", 5, ", ")) # "hello, world"
print(remove("hello, world", ", ")) # "helloworld"
line = "key: value"
print(after(line, ": ")) # "value"
print(before(line, ": ")) # "key"
full = "a/b/c.txt"
print(after_last(full, "/")) # "c.txt"
print(before_last(full, "/")) # "a/b"
true 6 12 hello, world helloworld value key c.txt a/b
from collections-strings
How it works
after(s, mark) / before(s, mark) — the piece past, or up to, a marker. Written as a pair because they chain: s.after("BEGIN").before("END") is the whole idiom, and it reads in the order the text does. A marker that is not there yields the WHOLE string rather than an error or an empty one. before on a line with no comment marker should be the line; after on a header that never appeared should be the body you were handed. An empty result would silently discard the text.
From the note above this builtin in the interpreter, where the reasoning was written down as it was built.
See also
before_last — documented in the same entry.