Quirrel4.41.0

types.String.endswith

Method on every string
string.endswith(suffix: string): any

Returns whether str ends with suffix.

The binding carries no declaration string, so the VM cannot report parameter names. The names above are from this page; the types and attributes still come from the VM. The VM also cannot tell an optional parameter from a variadic tail here, so read the brackets and any trailing ... from the prose below, not from the signature.

Parameters

suffixstringthe suffix to look for

Return value

true when the last suffix.len() bytes of str equal suffix, false otherwise. An empty suffix always matches; a suffix longer than str cannot match.

Notes

Takes exactly one argument. Same implementation as string.endswith; see the Notes on types.String.strip for how the two forms differ only in their reported attributes, not their behavior.

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

Example

examples/types/string/endswith.nut
println("\"hello world\".endswith(\"world\") =", "hello world".endswith("world"))
println("\"hello world\".endswith(\"hello\") =", "hello world".endswith("hello"))
Output:
"hello world".endswith("world") = true
"hello world".endswith("hello") = false

See also

startswithReturns whether str begins with prefix.
endswithReturns whether str ends with suffix.
stringclass index