TRIM
The TRIM function removes blanks or other characters from the end, the beginning, or both ends of a string expression. The data type of the result is the same as the string expression, but in a different format.
Arguments
The arguments are defined as follows:
stringExpression | Must be one of the following data types:
|
---|---|
direction | (Optional) Determines whether characters are removed from the end (TRAILING), the beginning (LEADING), or from both (BOTH) directions of the stringExpression. Must be one of the following values:
|
trimCharacter | (Optional) A single single-byte character set (SBCS) or double-byte character set (DBCS) character constant in the same data type as stringExpression When you specify a form other than UX", BX", or X", the utility assumes that the encoding scheme is EBCDIC and converts the encoding scheme of stringExpression. If you omit the trim character constant, the default is the padding character of stringExpression. The trim character data type must match the string expression data type. Otherwise the function will be rejected with an error. |
Results
The following example shows how to remove a leading 0 and trailing blanks from a string expression:
The inner TRIM option removes the leading 0s from the string expression, resulting in ‘1 ’ as the new string expression.
The outer TRIM option removes the trailing blanks from the new string expression, resulting in ‘1’.