Example - Trim, LTrim, RTrim Functions

The first part of this example uses the LTrim and RTrim functions to strip leading and trailing spaces, respectively, from a string variable. The final part of the example uses the Trim function alone to strip both types of spaces.  LCase and UCase are also shown in this example, as well as the use of nested function calls. The vertical pipe characters "|" that are added to the displayed messages may help you more easily see what's happening to the space characters.

Sub Main()     MyString = "  <-Trim->  "             ' Initialize string     TrimString = LTrim(MyString)          ' TrimString = "<-Trim->  "     MsgBox "|" & TrimString & "|"     TrimString = LCase(RTrim(MyString))   ' TrimString = "<-trim->  "     MsgBox "|" & TrimString & "|"     TrimString = LTrim(RTrim(MyString))   ' TrimString = "<-Trim->"     MsgBox "|" & TrimString & "|"       ' Using the Trim function alone achieves the same result.     TrimString = UCase(Trim(MyString))    ' TrimString = "<-TRIM->"     MsgBox "|" & TrimString & "|" End Sub