How it works

The Instruction operation "position" returns the zero-indexed position of the start of the first input string within the second input string.

  • If the first string is not found in the second string a NaN (Not a Number) value is returned
  • Only the first index position is returned
  • Note the result is zero indexed

"Position" Examples

Example 1: Basic position

In this example the value "on" is found in the second string "zone", it returns 1, as "z" is at position "0" and "on" starts at position 1.

<instruction operation="position">
	<input value="on"/>
	<input value="zone"/>
</instruction>
1

Example 2: String not found

In this example a NaN value is returned, this is because the Value "zone" is not found within the value "on", obviously.

<instruction operation="position">
	<input value="zone"/>
	<input value="on"/>
</instruction>
NaN

Example 3: Multiple Matches

In this example only the first index position is returned, so the value "-" is found at position 2 and all subsequent "-" within our value are ignored.

<instruction operation="position">
	<input value="-"/>
	<input value="10-11-10-"/>
</instruction>
2



Last Modified: Thu, 15 Jan 2015