COL1 Function

The COL1 function returns the column position of the character immediately preceding the string returned by the most recent FIELD function.

Format

COL1( )

Description

After the execution of a FIELD function, the COL1 function returns the column position immediately preceding the selected substring. Although the COL1 function takes no arguments, the parentheses are required to identify it as a function.

If no FIELD function precedes the COL1 function, a value of zero is returned. If the delimiter expression of the FIELD function is null or if the string is not found, the COL1 function returns a zero value.

The COL1, COL2, INDEX, and FIELD functions, with the substring assignment statement ([ ]=), may be used to perform array processing for strings with delimiters other than the attribute mark (CHAR(254)), value mark (CHAR(253)), and subvalue mark (CHAR(252)).

Example

To determine the column position before the third word in a string STRING, the code might read:

WORD = FIELD(STRING, " ", 3)

POS = COL1( )

If STRING contains "IT WAS TWENTY YEARS AGO TODAY", WORD contains "TWENTY" and POS contains "7". With this information, the string may be cut off after the second word with:

STRING = STRING[1, POS]

and STRING contains " IT WAS ".

In the next application, the NAMES string contains a list of names separated by commas (,). To replace a name, the substring assignment statement is used, but the COL1 function is necessary to determine where the replacement should start.

CURR.NAME = FIELD( NAMES, ",", 2)

IF NEW.NAME <> "" THEN

   BEG.COL = COL1( ) + 1

   LENGTH = LEN( CURR.NAME )

   NAMES[BEG.COL, LENGTH] = NEW.NAME

END

See Also

Statement and Function Reference