How to: |
GET_TOKEN extracts a token (substring) based on a string that can contain multiple characters, each of which represents a single-character delimiter.
GET_TOKEN(string, delimiter_string, occurrence)
where:
Alphanumeric
Is the input string from which the token will be extracted. This can be an alphanumeric field or constant.
Alphanumeric constant
Is a string that contains the list of delimiter characters. For example, '; ,' contains three delimiter characters, semi-colon, blank space, and comma.
Integer constant
Is a positive integer that specifies the token to be extracted. A negative integer will be accepted in the syntax, but will not extract a token. The value zero (0) is not supported.
The following request defines an input string and two tokens based on a list of delimiters that contains the characters comma (,), semicolon (;), and slash (/).
DEFINE FILE EMPLOYEE InputString/A20 = 'ABC,DEF;GHI/JKL'; FirstToken/A20 WITH DEPARTMENT = GET_TOKEN(InputString, ',;/', 1); FourthToken/A20 WITH DEPARTMENT = GET_TOKEN(InputString, ',;/', 4); END TABLE FILE EMPLOYEE PRINT InputString FirstToken FourthToken WHERE READLIMIT EQ 1 ON TABLE SET PAGE NOLEAD ON TABLE SET STYLE * GRID = OFF,$ END
The output is shown in the following image. The first token was extracted using the comma (,) as the delimiter. The fourth token was extracted using the slash (/) as the delimiter.