- Reference
- Script reference
- Strings and buffers
strfind
Searches a string for a substring
Description#
strfind( const string[], const sub[], bool:ignorecase=false, index=0 )
Search the haystack string for a needle sub. Optionally ignore case and start at an offset in the haystack.
Parameters#
string | String to be searched (the haystack) |
sub | The string we're looking for (the needle) |
ignorecase (optional) | If set to true, the search will ignore case |
index (optional) | Start at an offset different than the start of the haystack string |
Return value#
Returns the offset of sub in string if successful.
Returns -1 if no occurrence of sub was found in string.
The returned offset is always relative to the start of the string, even if a search offset is given.
Example usage#
new x;
new s{20} = "CatDogAnt";
x = strfind(s, "Dog");
// x is now 3Last updated Sep 2, 2019