The FIELD function searches through a string and returns a specified substring, based on a delimiter and the number of occurrences to search for.
Format
FIELD(expr, delimiter, group_position, {groups_returned}) |
Parameter(s)
expr |
An expression evaluating to the string to be searched through. |
delimiter |
An expression evaluating to the delimiter to be searched for. Only one character is accepted as a delimiter; any subsequent characters is ignored. |
group_position |
An expression evaluating to the occurrence of the delimiter to be used as an upper value. |
{groups_returned} |
Number of substrings separated by the specified delimiter to be returned. |
Description
The FIELD function returns the substring in an expression which lies between the n-1 and nth occurrences of the delimiter. If n is 1, the substring from the beginning of the expression to the first occurrence of the delimiter is returned. The delimiter can be any string, including attribute, value, and subvalue marks. It is used to designate the start and end of the substring.
The FIELD( ) function supports an optional fourth parameter. This specifies the number of groups to be returned. Specifying 1 as the fourth parameter is equivalent to omitting it. The function has this format:
FIELD(string, delimiter, group_position, groups_returned) |
If the variable string contains:
ABC*DEFG*HIJKL*MNOPQ*RSTU*VWXYZ |
then FIELD( ) returns:
FIELD(string,'*',3,2) = HIJKL*MNOPQ |
NOTE |
The fourth parameter removes any need to use ICONV(variable,'G...') type of text extracts, and allows the user to write easier to read, more efficient programs. |
Example
If STRING contains "NOW IS THE TIME", the variable THIRD can be assigned the third word of the string (THE) with:
THIRD = FIELD(STRING, " ", 3) |
In the next application, Attribute 1 of the MEMBER array holds the member’s full name, and Attribute 8 holds the date on which the customer first joined the health club. The FIELD function is used to isolate the month from the rest of a date in external format, in order to determine if the customer's annual fee is due.
NOW = FIELD(TIMEDATE( ) , " " , 4) MEM.DATE = MEMBER<8> MEM.DATE = OCONV(MEM.DATE , "D") MONTH = FIELD(MEM.DATE , " " , 2) IF MONTH = NOW THEN DUES.OWED : = MEMBER<1> END |
See Also