Sometimes, you will find you need to remove trailing spaces from a string. There are 3 functions for this. Trim, LTrim, RTrim. Trim removes spaces from either end of a string. LTrim removes spaces from the left end of a string. RTrim removes spaces from the right end of a string. They all use the following syntax:
Trim(String)
The following code fills String1 with ' Hello World ', then fills Text1, Text2, Text3, Text4 displaying the results of using nothing, Trim, LTrim and RTrim respectively
'// Declare the variable
Dim sString As String
'// Fill the variable
sString = " Hello World "
'// Display plain string
Text1.Text = sString
'// Display string using Trim
Text2.Text = Trim(sString)
'// Display string using LTrim
Text3.Text = LTrim(sString)
'// Display string using RTrim
Text4.Text = RTrim(sString)
Comments