Reference · Strings
ends_with
signature
ends_with(str, str) -> boolWhat it does
Whether the text ends with a suffix. The comparison is exact: case matters and the suffix is plain text, not a pattern. For a file extension in any case, lower the text first.
Examples
print(ends_with("hello", "lo"), ends_with("hello", "LO"))print(ends_with("photo.png", ".png"), ends_with("photo.PNG", ".png"))print(ends_with(lower("photo.PNG"), ".png"))output
true falsetrue falsetrueEdge cases
- Every string ends with
"", the empty string included. - A string ends with itself; a suffix longer than the text is
false. - Characters, not bytes: an accented letter at the end matches as one character.
print(ends_with("hello", ""), ends_with("", ""))print(ends_with("hello", "hello"), ends_with("hello", "xhello"))print(ends_with("café", "fé"))output
true truetrue falsetrueErrors
An argument that is not a string, on either side, is a runtime error, not an error
value: null and numbers are refused. Give a null field ?? "" first.
this one fails
print(ends_with(null, "a"))output
line 1: `ends_with` expects a str as argument 1, got nullChaining
In a pipeline the text comes first and the suffix is the argument:
print("x.txt" | ends_with(".txt"))print(["img.png", "a.jpg", "b.PNG"] | filter((f) => lower(f) | ends_with(".png")))print(`photos/${uuid()}.jpg` | ends_with(".jpg"))output
true["img.png", "b.PNG"]trueSee also
starts_with, contains, lower, slice, re.test
Thread
Thread 0 posts
On ends_with(): questions, tips, corrections, and code that uses it.
No posts yet. The first one opens the thread.
Edit this page on GitHub · every example's output was made by running it (tools/refcheck.mjs) · questions on Discord or r/quillo