Contents | Prev | Next

7.2.48 The pos function

Description

The pos function accepts up to three of the parameters described below (the last parameter is optional), searches for one string in another string, and returns the position of the first string in the second string, or zero if the first string was not found in the second string.

Parameter

  1. The first parameter needle is an expression of string type or char type, and is the string to search for.
  2. The second parameter haystack is an expression of string type or char type, and is the string to be searched.
  3. The third parameter start is an expression of integral type, and specifies the position in haystack to begin searching for needle. If start is omitted then haystack is searched starting from position one. If start is greater than the length of haystack then zero is returned.

Example

   pos('o', 'Hello world')     returns  5
   pos('o', 'Hello world', 1)  returns  5
   pos('o', 'Hello world', 6)  returns  8
   pos('o', 'Hello world', 9)  returns  0

Portability

Operating Systems: All
Standard Pascal: No

Contents | Prev | Next