Reference · Strings

starts_with

signature
starts_with(str, str) -> bool

What 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 falsetrue

Edge cases

print(starts_with("hello", ""), starts_with("", ""))print(starts_with("hello", "hello"), starts_with("hello", "hellos"))print(starts_with("héllo", "hé"))
output
true truetrue falsetrue

Errors

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 int

Chaining

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"]true

See also

ends_with, contains, index_of, slice, re.test

Thread
6Useful? Like it, or add to its thread below.

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