strpos()

Returns the position of a string within another.

Synopsis

int strpos(string s, string searchstr[, int startPos = 0]);

Parameters

Parameter Description
s String to be examined
searchstr String searched for
startPos Optional parameter. Start position for the search in the string.

Return value

Position number, if searchstr is not found within s -1, or in the event of an error -2 is returned.

Errors

Missing/incorrect arguments

Description

Returns the position (in Bytes) of the string searchstr (the first occurrence of search) within the string s. For the first Byte of s it is equal to zero, for the second 1 etc. If searchstr is not found within s, -1, in the event of an error -2, is returned.

Example

main()
{
  DebugN(strpos("Orangejuice","juice", 0)); // Returns 6
  DebugN(strpos("Orangejuice","juice", 8)); /* Returns -1
  (searched string not found) */
  DebugN(strpos("Orangejuice","juice", 6)); // Returns 6
}

Assignment

Strings

Availability

CTRL