Trim, LTrim, RTrim (function)

<< Click to Display Table of Contents >>

Trim, LTrim, RTrim (function)

Removes the leading or trailing space characters from a string.

LTrim(String) removes the leading spaces.

RTrim(String) removes the trailing spaces.

Trim(String) removes both leading and trailing spaces.

Example:

Sub Main

 MyString = "   <-Trim->   "

 TrimString = LTrim(MyString)         ' "<-Trim->   ".

 MsgBox "|" & TrimString & "|"

 TrimString = RTrim(MyString)         ' "   <-Trim->".

 MsgBox "|" & TrimString & "|"

 TrimString = LTrim(RTrim(MyString))  ' "<-Trim->".

 MsgBox "|" & TrimString & "|"

 TrimString = Trim(MyString)          ' "<-Trim->".

 MsgBox "|" & TrimString & "|"

End Sub