TRIMV: Removing Characters From a String

How to:

Available Languages: reporting

The TRIMV function removes leading and/or trailing occurrences of a pattern within a character string. TRIMV is similar to TRIM. However, TRIMV allows the source string and the pattern to be removed to have AnV format.

TRIMV is useful for converting an An field to an AnV field (with the length in bytes containing the actual length of the data up to the last non-blank character).

Syntax: How to Remove Characters From a String

TRIMV(trim_where, source_string, upper_limit, pattern, pattern_limit,  output)

where:

trim_where

Alphanumeric

Is one of the following, which indicates where to remove the pattern:

'L' removes leading occurrences.

'T' removes trailing occurrences.

'B' removes both leading and trailing occurrences.

source_string

Alphanumeric of type An or AnV

Is the source string to be trimmed. It can be the string enclosed in single quotation marks ('), or the field containing the string. If it is a field, it can have An or AnV format. If it is a field of type AnV, its length is taken from the length in bytes stored in the field. If upper_limit is smaller than the actual length, the source string is truncated to this upper limit.

upper_limit

Integer

Is the upper limit for the length of the source string.

pattern

Alphanumeric of type An or AnV

Is the pattern to remove from the string, enclosed in single quotation marks ('). If it is a field, it can have An or AnV format. If it is a field of type AnV, its length is taken from the length in bytes stored in the field. If pattern_limit is smaller than the actual length, the pattern is truncated to this limit.

plength_limit

Integer

Is the limit for the length of the pattern.

output

Alphanumeric of type An or AnV

Is the field to which the result is returned, or the format of the output value enclosed in single quotation marks ('). The field can be in AnV or An format.

If the output format is AnV, the length is set to the number of characters left after trimming.

Example: Creating an AnV Field by Removing Trailing Blanks

TRIMV creates an AnV field named TITLEV by removing trailing blanks from the TITLE value:

TABLE FILE MOVIES                                                 
PRINT DIRECTOR                                          
COMPUTE TITLEV/A39V = TRIMV('T', TITLE, 39, ' ', 1, TITLEV);
BY CATEGORY                                                       
END

Here are the first 10 lines of the output:

CATEGORY  DIRECTOR         TITLEV 
--------  --------         ------  
ACTION    SPIELBERG S.     JAWS
          VERHOVEN P.      ROBOCOP
          VERHOVEN P.      TOTAL RECALL
          SCOTT T.         TOP GUN
          MCDONALD P.      RAMBO III
CHILDREN                   SMURFS, THE
          BARTON C.        SHAGGY DOG, THE
                           SCOOBY-DOO-A DOG IN THE RUFF
          GEROMINI         ALICE IN WONDERLAND
                           SESAME STREET-BEDTIME STORIES AND SONGS