Position

4D - Documentation   Français   English   German   Spanish   4D v11 SQL, Command Theme List   4D v11 SQL, Command Alphabetical List   4D v11 SQL, Constant Theme List   Back   Previous   Next

version 11 (Modified)


Position (find; aString{; start{; lengthFound{; *}}}) Number

ParameterTypeDescription
findStringString to find
aStringStringString in which to search
startNumberPosition in string where search will start
lengthFoundLongintLength of string found
**If passed: diacritic-sensitive search
Function resultNumberPosition of first occurrence

Description

Position returns the position of the first occurrence of find in aString.

If aString does not contain find, it returns a zero (0).

If Position locates an occurrence of find, it returns the position of the first character of the occurrence in aString.

If you ask for the position of an empty string within an empty string, Position returns zero (0).

By default, the search begins at the first character of aString. The optional start parameter can be used to specify the character where the search will begin in aString.

The lengthFound parameter, if passed, returns the length of the string actually found by the search. This parameter is necessary to be able to correctly manage letters that can be written using one or more characters (e.g.: æ and ae, ß and ss, etc.).

Note that when the * parameter is passed (diacritic-sensitive mode, see below), these letters are not considered as equivalent (æ # ae); in diacritic-sensitive mode, lengthFound is always equal to the length of find (if an occurrence is found).

The * parameter, if passed, indicates that the search must be diacritic-sensitive, i.e. it must take the case of the characters and diacritic marks into account (a # A, à # a, etc.)

Warning: You cannot use the @ wildcard character with Position. For example, if you pass "abc@" in find, the command will actually look for "abc@" and not for "abc" plus any character.

Examples

1. This example illustrates the use of Position. The results, described in the comments, are assigned to the variable vlResult.

   vlResult := Position ("ll"; "Willow")  ` vlResult gets 3 
   vlResult := Position (vtText1; vtText2)  ` Returns first occurrence of vtText1 in vtText2
   vlResult := Position ("day"; "Today is the first day";1) ` vlResult gets 3
   vlResult := Position ("day"; "Today is the first day";4) ` vlResult gets 20
   vlResult := Position ("DAY"; "Today is the first day";1;*) ` vlResult gets 0

   vlResult := Position ("œ"; "Bœuf";1;$length) ` vlResult =2, $length = 1

2. In the following example, the lengthFound parameter can be used to search for all the occurrences of "aegis" in a text, regardless of how it is written:

   $start:=1 
   Repeat
      vlResult := Position ("aegis";$text;$start;$lengthfound)
      $start:= $start+$lengthfound
   Until(vlResult =0)

See Also

Comparison Operators, Substring.


4D - Documentation   Français   English   German   Spanish   4D v11 SQL, Command Theme List   4D v11 SQL, Command Alphabetical List   4D v11 SQL, Constant Theme List   Back   Previous   Next