POS(


General Forms:
pos.gif
2.      POS(field_variable)

Where:

     hh           = two hexadecimal digits (0-9, A-F)


The first form of the POS( function returns the position of the first occurrence of a character in an alpha variable, string or string function that satisfies the specified relationship. The POS( function is valid wherever a numeric expression is legal.

The character used for comparison follows the relational operator. If more than one character is supplied then only the first character of the string is used for comparison.

The position of the first character that satisfies the relation, is returned as a numeric value. If the relation is not satisfied then POS( returns zero.

If a minus sign precedes the alpha variable, literal, or string function being searched, POS( returns the position of the last character satisfying the relation.

The second form is used to return the start position of the specified field, e.g:

StartPos = POS(.Name$)

The LEN( function can be used to return to size of the field.

UTF-8

If the KCML uses UTF-8 encoding, i.e. the environment variable USING_UTF8 is set, then KCML will first inspect the character to see if it a plausible UTF-8 character, which may be multibyte, and then search the string assuming it to be composed of valid UTF-8 characters. If the character is not UTF-8 then KCML will fall back to the default byte mode where no encoding is assumed and only the first byte of the matching string is used. To guarantee that POS does not interpret the string as UTF-8 ensure the search character string is exactly one byte long.

The offset returned will always be in bytes. To convert a byte offset to UTF-8 characters use ULEN8() e.g.:

nChars = ULEN8(STR(s$,,nOffset-1))

Example:

DIM test$26
test$ = "abcdefghijklmnopqrstuvwxyz"
Test = POS(test$ = "o")

Syntax examples:

period = POS(record$ = ".")
IF (POS(file$() = "#") == 0)
big = POS(-after$ <> STR(tst$,status,1))
tmp = pos(.name$)

See also:

FLD(