Template Engine language reference > Template Engine utilities > String functions > $string.indexOf

$string.indexOf
This function searches for a specific substring in the input string, and returns the position (zero based index) of the first occurrence of the specified substring. If the substring is not found, it returns -1. You can add an optional index argument to this function to specify the position where to start in the input string.
Syntax
$string.indexOf(<inStr>, <subStr>[, <index>])
inStr
subStr
index
Optional start index (zero based) that sets the start position for the search. If not set the search will start from the first character in the input string (i.e. index=0).
Template examples
Example 98
Template
#set($str='But to be able to do this you have to do that!')
#set($pos=$string.indexOf($str, 'to'))
Position is: $pos
Output
Position is: 4
 
Example 99
Template
#set($str='But to be able to do this you have to do that!')
#set($pos=$string.indexOf($str, 'to', 5))
Position is: $pos
Output
Position is: 15
 
OpenText StreamServe 5.6.2 Updated: 2018-01-26