str_find(src, target, start_from=0)
Finds the first occurrence of the substring target in src
.
This script returns the index (i.e. byte) of the the first occurrence of substring target
in str
, starting from the given (optional) position.
The result may not correspond to the actual position of the first character of target in case src
contains multi-byte or variable-length encoded characters.
The string is zero-indexed.
Parameters
src:
source string.
target:
substring to search.
start_from:
optional starting position (default 0).
Return Value
The index of the first occurrence of target in src
, -1 if target
is not found in src
.
Example command:
str_find("Hello World!", "o")
- returns 4
str_find("Hello World!", "lo")
- returns 3
str_find("Hello World!", "o", 5)
- returns 7
str_find("abc", "z")
- returns -1