STRTOKEN: Extracting a Substring Based on Delimiters

How to:

The STROKEN function returns a substring, that consists of a string's characters from the beginning of a string to a specified character, called a delimiter.

To use this function, you must import the function library MNTUWS. For more information on importing this library see Calling a Function.


Top of page

x
Syntax: How to Extract a Substring
STRTOKEN(string, delimiters)

where:

string

Alphanumeric

Is the character string, or a variable that contains the string enclosed in double quotation marks.

delimiters

Alphanumeric

Is a character string, or variable enclosed in double quotation marks that contains a list of delimiters. Separate the delimiters with semicolons.



Example: Extracting a Substring

STRTOKEN returns a substring of the first five STREET values in the VIDEOTRK data source based on the delimiters period, space, or asterisk.

MAINTAIN FILE VIDEOTRK
MODULE IMPORT (MNTUWS);
FOR ALL NEXT CUSTID INTO CSTACK ;
COMPUTE CNT/I5 = 1;
TYPE "   ";
REPEAT WHILE CNT LE 5;
COMPUTE SUBSTREET/A20 = STRTOKEN(CSTACK(CNT).STREET,".; ,*");
TYPE " STREET =        <CSTACK(CNT).STREET"
TYPE " SUBSTREET =     <SUBSTREET "
COMPUTE CNT = CNT +1;
ENDREPEAT
END

The output is:

STREET =        86 ELLIOTT AVE.
SUBSTREET =     86
STREET =        7 DAVENPORT LA.
SUBSTREET =     7
STREET =        8 MAGNOLIA LA.
SUBSTREET =     8
STREET =        35 POWELL ST.
SUBSTREET =     35
STREET =        10 COW LA.
SUBSTREET =     10

Information Builders