Trim, Trim$, LTrim, LTrim$, RTrim, RTrim$ (functions)

Syntax Trim[$](string) LTrim[$](string) RTrim[$](string)
Description Functions return the following.
Function Returns
Trim Copy of the passed string expression (string) with both the leading and trailing spaces removed.
LTrim String with the leading spaces removed,
RTrim String with the trailing spaces removed.
Trim$, LTrim$, and RTrim$ String
Trim, LTrim, and RTrim String variant.
Null is returned if string is Null.
Comments Trim$ returns a String , whereas Trim returns a String variant. Null is returned if text is Null .
Example 1

                           'This first example uses the Trim$ function to extract the
                           'nonblank part of a string and display it.
                           Const crlf = Chr$(13) + Chr$(10)
                           Sub Main()
                               text$ = " This is text "
                               tr$ = Trim$(text$)
                               MsgBox "Original =>" & text$ & "<=" & crlf & _
                               "Trimmed =>" & tr$ & "<="
                           End Sub
                        
Example 2

                           'This second example displays a right-justified string and its
                           'LTrim result.
                           Const crlf = Chr$(13) + Chr$(10)
                           Sub Main()
                               a$ = " <= This is a right-justified string"
                               b$ = LTrim$(a$)
                               MsgBox a$ & crlf & b$
                           End Sub
                        
Example 3

                           'This third example displays a left-justified string and its
                           'RTrim result.
                           Const crlf = Chr$(13) + Chr$(10)
                           Sub Main()
                               a$ = "This is a left-justified string. "
                               b$ = RTrim$(a$)
                               MsgBox a$ & "<=" & crlf & b$ & "<="
                           End Sub
                        
See Also LTrim, LTrim$ (functions); RTrim, RTrim$ (functions).