types.String.contains
Returns whether str contains substr.
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
substr | string | the substring to look for; must not be empty |
start | number | byte index to start searching from; defaults to 0 optional |
... | any | not a real parameter; see Notes repeats |
Return value
true if substr occurs at or after start, false otherwise - always a bool, never null. This is the difference from types.String.indexof: the same scan, but contains never reports "not found" as anything other than false. A negative or out-of-range start gives false, not a wraparound search.
Errors
Throws empty substring when substr is "".
Notes
Takes 1 or 2 arguments: start is optional. A third argument is silently ignored.
Example
println("\"hello\".contains(\"ell\") =", "hello".contains("ell"))
println("\"hello\".contains(\"xyz\") =", "hello".contains("xyz"))
// unlike indexof, a negative start does not wrap: it just cannot match.
println("\"hello\".contains(\"l\", -2) =", "hello".contains("l", -2))Output:
"hello".contains("ell") = true
"hello".contains("xyz") = false
"hello".contains("l", -2) = falseSee also
indexof | Returns the byte index of the first occurrence of substr in str. |
startswith | Returns whether str begins with prefix. |
| string | class index |