Previous Topic Next topic Print topic


TRIM Function

Purpose

Strips blanks or specified characters from the beginning and end of a character string value and returns the resulting string.

Syntax

TRIM(string[,a,b])

Parameters

string is a character string value (variable or constant). a, if present, is a string consisting of the set of characters to be trimmed from the beginning of string. b, if present, is a string consisting of the set of characters to be trimmed from the end of string.

Description

The TRIM built-in function strips the characters specified in a from the beginning of string and the characters specified in b from the end of string and returns the resulting string.

If the second and third arguments are not present, blanks are trimmed from the beginning and end of the first argument.

Examples

The following example returns the values shown in the comment.

DECLARE
   S CHAR(25)VARYING, 
   A CHAR(5);
A = 'ABC';
S = TRIM(A);            /* S = 'ABC' */
S = TRIM(' HELLO');     /* S = 'HELLO' */
S = TRIM(' GOODBYE ');  /* S = 'GOODBYE' */
S = TRIM('');           /* S = '' null string */
S = TRIM('abcdefghi','cba', 'high');    /* S = 'def' */
S = TRIM('abc','abc','abc')   /* S = '' null string */

Restrictions

None.

Previous Topic Next topic Print topic