See Also

Mid, Mid$ Function3XXKYW5


LTrim, LTrim$, RTrim, RTrim$, Trim, Trim$ Functions Example

The example uses LTrim and RTrim, to strip leading and trailing spaces from a string variable.  The stripping of both leading and trailing spaces can be more efficiently done using the Trim function.  To try this example, paste the code into the Declarations section of a form.  Then press F5 and click the form.

 

Sub Form_Click ()

   Dim Msg, NL, TestStr, TestStr1        ' Declare variables.

   NL = Chr(10)                          ' Define newline.

   TestStr = "  Test String  "

   TestStr1 = LTrim(RTrim(TestStr))      ' Strip spaces left and right.

   Msg = "The original TestStr """ & TestStr & """ was "

   Msg = Msg & Len(TestStr) & " characters long. There were two "

   Msg = Msg & "leading spaces and two trailing spaces." & NL & NL

   Msg = Msg & "The TestStr returned after stripping the spaces "

   Msg = Msg & "is """ & TestStr1 & """ and it contains only "

   Msg = Msg & Len(TestStr1) & " characters."

   MsgBox Msg                            ' Display message.

End Sub