Reference · Strings
starts_with
signature
starts_with(str, str) -> boolWhat it does
Whether the text begins with a prefix. The comparison is exact: case matters and the prefix is plain text, not a pattern.
Examples
print(starts_with("hello", "he"), starts_with("hello", "He"))print(starts_with("/api/users", "/api/"))output
true falsetrueEdge cases
- Every string starts with
"", the empty string included. - A string starts with itself; a prefix longer than the text is
false. - Characters, not bytes:
starts_with("héllo", "hé")istrue.
print(starts_with("hello", ""), starts_with("", ""))print(starts_with("hello", "hello"), starts_with("hello", "hellos"))print(starts_with("héllo", "hé"))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(starts_with("abc", 1))output
line 1: `starts_with` expects a str as argument 2, got intChaining
In a pipeline the text comes first and the prefix is the argument:
print("Hello" | starts_with("H"))print(["/api/a", "/web", "/api/b"] | filter((p) => p | starts_with("/api/")))print(("Hello" | starts_with("H")) && ("Hello" | ends_with("o")))output
true["/api/a", "/api/b"]trueSee also
ends_with, contains, index_of, slice, re.test
Thread
Thread 0 posts
On starts_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