Strtok Function

Action

Finds the next token in a string.

Include file

Kernel.bdh

Syntax

Strtok( in sTokenString  : string allownull,
        in sDelimiterSet : string ): string;

Return value

Next token found in sTokenString. This function returns an empty string when no more tokens are found. Each call modifies sTokenString by substituting a null character for each delimiter that is encountered.

Parameter Description
sTokenString Defines the string to search in. Each call modifies this parameter by substituting a null character for each delimiter that is encountered.
sDelimiterSet Defines a set of characters that subdivide the tokens.

Example

dcltrans
  transaction TStrtok
  var
    sTokenString, sDelimiterSet, sToken: string;
  begin
    sTokenString := "apples+peaches*bananas/physical training="
                    "very healthy";
    sDelimiterSet := "+*/=";
    write("Tokens found: "); writeln;
    sToken := Strtok(sTokenString, sDelimiterSet);

    while sToken <> "" do
      write(sToken); write(", ");
      sToken := Strtok(NULL, sDelimiterSet);
    end;
  end TStrtok;

Output

Tokens found:
apples, peaches, bananas, physical training, very healthy,