string.endswith
Defined in module
"string"from "string" import endswithReturns whether str ends with suffix.
Parameters
str | string | the string to test |
suffix | string | the 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
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", "") = trueSee also
startswith | Returns whether str begins with prefix. |
| string | module index |