Example:

  1. ' 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.

    ' LCase and UCase are also shown in this example as well as the use

    ' of nested function calls

    Sub Main

    1. 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