strIndexOf

Determines if one string is a substring of another.

Note:

Use the Special String Operators for string concatenation, string inclusion, and simple comparison.

Type and Usage

Parameters

Takes two parameters:

  • The first parameter is a string.

  • The second parameter is the possible substring.

Output

  • If the second string is a substring of the first, returns an index value that indicates where in the first string the substring begins. The first character has an index value of 0.

  • If the second string is not a substring of the first, returns a value of -1.

Example

Evaluates whether xy is a substring of xyz and returns the index value 0:

<$if strIndexOf("xyz","xy") >=0$> check for substring <$endif$>

Evaluates whether yz is a substring of xyz and returns the index value 1:

<$if strIndexOf("xyz","yz") >=0$> check for substring <$endif$>

Evaluates whether ab is a substring of xyz and returns the index value –1 to indicate that this is not a substring:

<$if strIndexOf("xyz","ab") >=0$> check for substring <$endif$>