...
Returns the character position of one string inside anothera sub-string within a string.
Syntax
indexOf(stringToTest, stringToLookFor)
Argument | Type | Description |
---|---|---|
stringToTest | String | The string that will be searched. |
stringToLookFor | String | The sub-string to look for within the string. |
If the string does not exist, indexOf returns 0.
If there are multiple hits for the sub-string, indexOf returns the position of the first occurrence.
Examples
indexOf("Thomas Troubridge", " ")
...
indexOf("Thomas Troubridge", "bridge")
Returns 12, the start of the sub-string "bridge".
indexOf("Thomas Troubridge", "x")
Returns 0, as the sub-string "x" does not exist in the string.
indexOf("Space1, Space2 and Space3" "e")
Returns 5, which is the first occurrence of "e". It does not return subsequent occurrences at positions 13 and 24.
Using indexOf in a script:
Code Block |
---|
do( $start = indexOf(in.fileName, "_") + 1, $end = $start + 8, $date = substring(in.fileName, $start, $end) ) |
...