before
Builtin index · Collections & strings
result = after(s, mark)
Input: s, mark · Output: result
What it is
s and mark are Strs. after returns the piece of s past the first mark; before returns the piece up to it. after_last/before_last search from the other end. A mark that is not present leaves s whole (returned unchanged), never empty.
Overloads
One call shape — this function is not overloaded.
| Code | Input | Output | Description |
result = after(s, mark) | s Strnot documented yetmark Strnot documented yet | result Str | Returns a Str. |
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
after — documented in the same entry.