TRIM_: Removing Leading Characters, Trailing Characters, or Both From a String

How to:

The TRIM_ function removes all occurrences of a single character from either the beginning or end of a string, or both.


Top of page

x
Syntax: How to Remove Leading Characters, Trailing Characters, or Both From a String
TRIM_(trim_where, trim_character, source_string) 

where:

trim_where

Keyword

Defines where to trim the source string. Valid values are:

  • LEADING, which removes leading occurrences.
  • TRAILING, which removes trailing occurrences.
  • BOTH, which removes leading and trailing occurrences.
trim_character

Alphanumeric

Is a single character, enclosed in single quotation marks ('), whose occurrences are to be removed from source_string. For example, the character can be a single blank (‘ ‘).

source_string

Alphanumeric

Is the string to be trimmed.

The data type of the returned string is AnV.



Example: Trimming a Character From a String

In the following request, TRIM_ removes leading occurrences of the character ‘B’ from the DIRECTOR field:

TABLE FILE MOVIES
PRINT DIRECTOR AND
COMPUTE
TRIMDIR/A17 = TRIM_(LEADING, 'B', DIRECTOR);
WHERE DIRECTOR CONTAINS 'BR'
ON TABLE SET PAGE NOPAGE
END

The output is:

  DIRECTOR           TRIMDIR                              
  --------           -------                                      
  ABRAHAMS J.        ABRAHAMS J.      
  BROOKS R.          ROOKS R.         
  BROOKS J.L.        ROOKS J.L.       

WebFOCUS