LTrim, RTrim, and Trim Functions

Description

Returns a copy of a string without leading spaces (LTrim), trailing spaces (RTrim), or both leading and trailing spaces (Trim).

Syntax

LTrim(string)RTrim(string)Trim(string)

The string argument is any valid string expression. If string contains Null, Null is returned.

See Also

Left Function, Right Function.

Example

This example uses the LTrim and RTrim functions to strip leading and trailing spaces, respectively, from a string variable. It uses the Trim function alone to strip both types of spaces.


MyString = "  <-Trim->  "            ' Initialize string.= LTrim(MyString)            ' TrimString = "<-Trim->  ".= RTrim(MyString)            ' TrimString = "  <-Trim->".= LTrim(RTrim(MyString))    ' TrimString = "<-Trim->".
' Using the Trim function alone achieves the same result.= Trim(MyString)            ' TrimString = "<-Trim->".