Tokens are strings that are separated by delimiter characters. For example, if the characters space (" ") and comma (",") are defined as delimiters, the string "CALL PROGRAM ARG1,ARG2,ARG3" can be broken down into the five tokens "CALL", "PROGRAM", "ARG1", "ARG2", and "ARG3". The function fetches one token at a time, based on an index value that refers to the position of the token within the string.
The strLib.getNextToken() function is overloaded, so you can call the same function name with different configurations of parameters and return values. The following form of the function is preferred:
strLib.getNextToken( source STRING | CHAR | DBCHAR | MBCHAR | UNICODE inOut, index INT inOut, delimiters STRING | CHAR | DBCHAR | MBCHAR | UNICODE in) returns (token STRING? | CHAR? | DBCHAR? | MBCHAR? | UNICODE?)
The following form is available for compatibility with earlier versions:
strLib.getNextToken( target CHAR | DBCHAR | MBCHAR | UNICODE inOut, source CHAR | DBCHAR | MBCHAR | UNICODE in, index INT inOut, substringLength INT inOut, delimiters STRING in) returns (result INT)
In this example, the program uses the updated value of i to loop through a string and store the tokens in an array.
commandLine STRING = "CALL PROG1 arg1,arg2"; delimiters STRING = " ,"; // space and comma delimiters i INT = 1; max INT; tokens STRING[0]; token STRING? = ""; function readParms() max = strLib.byteLen(commandLine); while( i < max) // i is updated below token = StrLib.getNextToken(commandLine, i, delimiters); if (token != null) tokens.appendElement(token); end // if end // while end // main
Platform | Issue |
---|---|
JavaScript generation | The function strLib.getNextToken() is not supported. |