Quirrel4.41.0

string.endswith

Defined in module "string"
from "string" import endswith
pure fastcall endswith(str: string, suffix: string): bool

Returns whether str ends with suffix.

Parameters

strstringthe string to test
suffixstringthe suffix to look for

Return value

true when the last suffix.len() characters of str equal suffix, false otherwise.

Notes

An empty suffix always matches: every string ends with the empty string. A suffix longer than str cannot match and gives false without reading past the start of str.

The comparison is a raw byte compare; there is no case-insensitive form.

Example

examples/string/endswith.nut
from "string" import endswith

println("endswith(\"hello world\", \"world\") =", endswith("hello world", "world"))
println("endswith(\"world\", \"hello world\") =", endswith("world", "hello world")) // suffix longer than str: always false

// the empty suffix always matches
println("endswith(\"anything\", \"\") =", endswith("anything", ""))
Output:
endswith("hello world", "world") = true
endswith("world", "hello world") = false
endswith("anything", "") = true

See also

startswithReturns whether str begins with prefix.
stringmodule index