This topic covers the Trim, LTrim and 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.
' 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