How to: |
Available Languages: reporting, Maintain
The GETTOK function divides a character string into substrings, called tokens. In order to use GETTOK, the data must have a specific character, called a delimiter, that occurs in the string and separates the string into tokens. GETTOK returns the token specified by the token_number argument. GETTOK ignores leading and trailing blanks in the parent character string.
For example, suppose you want to extract the fourth word from a sentence. You can use the space character for a delimiter and four for the token_number. GETTOK divides the sentence into words using this delimiter, then extracts the fourth word. If the string is not divided by the delimiter, use the PARAG function for this purpose.
GETTOK(infield, inlen, token_number, 'delim', outlen, outfield)
where:
Alphanumeric
Is the field containing the parent character string.
Integer
Is the length of the parent string in characters. If this argument is less than or equal to 0, the function returns spaces.
Integer
Is the number of the token to extract. If this argument is positive, the tokens are counted from left to right. If this argument is negative, the tokens are counted from right to left. For example, -2 extracts the second token from the right. If this argument is 0, the function returns spaces. Leading and trailing null tokens are ignored.
Alphanumeric
Is the delimiter in the parent string enclosed in single quotation marks. If you specify more than one character, only the first character is used.
Note: In Dialogue Manager, to prevent the conversion of a delimiter space character (' ') to a double precision zero, include a non-numeric character after the space (for example, '%'). GETTOK uses only the first character (the space) as a delimiter, while the extra character (%) prevents conversion to double precision.
Integer
Is the maximum size of the token. If this argument is less than or equal to 0, the function returns spaces. If the token is longer than this argument, it is truncated; if it is shorter, it is padded with trailing spaces.
Alphanumeric
Is the name of the field that contains the token, or the format of the output value enclosed in single quotation marks. The delimiter is not included in the token.
GETTOK extracts the last token from ADDRESS_LN3 and stores the result in LAST_TOKEN.
The delimiter is a space:
TABLE FILE EMPLOYEE
PRINT ADDRESS_LN3 AND COMPUTE
LAST_TOKEN/A10 = GETTOK(ADDRESS_LN3, 20, -1, ' ', 10, LAST_TOKEN);
AS 'LAST TOKEN,(ZIP CODE)'
WHERE TYPE EQ 'HSM';
END
The output is:
LAST TOKEN ADDRESS_LN3 (ZIP CODE) ----------- ---------- RUTHERFORD NJ 07073 07073 NEW YORK NY 10039 10039 FREEPORT NY 11520 11520 NEW YORK NY 10001 10001 FREEPORT NY 11520 11520 ROSELAND NJ 07068 07068 JERSEY CITY NJ 07300 07300 FLUSHING NY 11354 11354
WebFOCUS |