Trim, LTrim, RTrim Functions

 

[L| R] Trim (String  )

 

Ltrim, Rtrim and Trim all Return a copy of a string with leading, trailing or both leading and trailing spaces removed.

 

Ltrim, Rtrim and Trim all return a string

 

Ltrim removes leading spaces.

Rtrim removes trailing spaces.

Trim removes leading and trailing spaces.

 

 

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.

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

' of nested function calls

 

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