STRIP: Removing a Character From a String

How to:

Available Languages: reporting, Maintain

The STRIP function removes all occurrences of a specific character from a string. The resulting character string has the same length as the original string but is padded on the right with spaces.

Syntax: How to Remove a Character From a String

STRIP(length, source_string, char, output)

where:

length

Integer

Is the number of characters in source_string and output, or a field that contains the number.

source_string

Alphanumeric

Is the string from which the character will be removed, or a field containing the string.

char

Alphanumeric

Is the character to be removed from the string. This can be an alphanumeric literal enclosed in single quotation marks, or a field that contains the character. If more than one character is provided, the left-most character will be used as the strip character.

Note: To remove single quotation marks, use two consecutive quotation marks. You must then enclose this character combination in single quotation marks.

output

Alphanumeric

Is the field that contains the result, or the format of the output value enclosed in single quotation marks.

Example: Removing Occurrences of a Character From a String

STRIP removes all occurrences of a period (.) from the DIRECTOR field and stores the result in a field with the format A17:

TABLE FILE MOVIES
PRINT DIRECTOR AND COMPUTE
SDIR/A17 = STRIP(17, DIRECTOR, '.', 'A17');
WHERE CATEGORY EQ 'COMEDY'
END

The output is:

DIRECTORS       SDIR
---------       ----
ZEMECKIS R.     ZEMECKIS R
ABRAHAMS J.     ABRAHAMS J
ALLEN W.        ALLEN W
HALLSTROM L.    HALLSTROM L
MARSHALL P.     MARSHALL P
BROOKS J.L.     BROOKS JL

Example: Removing Single Quotation Marks From a String

STRIP removes all occurrences of a single quotation mark (') from the TITLE field and stores the result in a field with the format A39:

TABLE FILE MOVIES
PRINT TITLE AND COMPUTE
STITLE/A39 = STRIP(39, TITLE, '''', 'A39');
WHERE TITLE CONTAINS '''' 
END

The output is:

TITLE                           STITLE
-----                           ------
BABETTE'S FEAST                 BABETTES FEAST
JANE FONDA'S COMPLETE WORKOUT   JANE FONDAS COMPLETE WORKOUT
JANE FONDA'S NEW WORKOUT        JANE FONDAS NEW WORKOUT
MICKEY MANTLE'S BASEBALLTIPS    MICKEY MANTLES BASEBALL TIPS

Example: Removing Commas From a String (Maintain)

STRIP removes all occurrences of a comma from the TITLE field:

MAINTAIN FILE MOVIES
FOR 10 NEXT MOVIECODE INTO MOVSTK
 WHERE TITLE CONTAINS ',';
COMPUTE I/I2=1;
REPEAT MOVSTK.FOCINDEX
TYPE "TITLE IS: <MOVSTK(I).TITLE"
COMPUTE NOCOMMA/A39=STRIP(39,MOVSTK().TITLE, ',',NOCOMMA);
TYPE "NEW TITLE IS: <NOCOMMA";
COMPUTE I=I+1
ENDREPEAT
END

The output is:

TITLE IS: SMURFS, THE
NEW TITLE IS: SMURFS THE