The string indexOf task finds the position (index) of a specific character or group of characters within a given string. By default, characters in a string are indexed from left to right. The indexOf task is also case-sensitive. In conjunction with other workflow tasks, this task is useful when you need to find the first instance (or all instances) of a specific character.
Suppose you are attempting to extract email domains from user email addresses, and you need to isolate the exact position of the @ symbol in the email address. Using indexOf will allow you to obtain the information you need.
In this example:
str variable has been statically set as abcabcdabcde.searchValue variable is abcd.fromIndex is set to 0, indicating the search should start at the beginning of the line. Numbering starts at zero.index will be 3, which represents the first instance of where “abcd” can be found in the str variable (at character position 3).
In this example:
str variable has been statically set as sales@itential.com.searchValue variable has been statically set as @.fromIndex is set to 0, indicating the search should start at the beginning of the line. Numbering starts at zero.index will be 5, because the first instance of the value @ occurs at character position 5 in the str variable.
indexOf task with str sales@itential.com and searchValue @