Left (function)

<< Click to Display Table of Contents >>

Left (function)

Left(String, n)

Returns a string consisting of the first n characters of the passed string String.

See also: Len, Mid, Right

Example:

Sub Main

 Dim LWord, Msg, RWord, SpcPos, UsrInp

 Msg = "Enter two words "

 Msg = Msg & "separated by a space character."

 UsrInp = InputBox(Msg)

 SpcPos = InStr(1, UsrInp, " ")                          ' Find space character

 If SpcPos Then

         LWord = Left(UsrInp, SpcPos - 1)                  ' Left word

         RWord = Right(UsrInp, Len(UsrInp) - SpcPos)        ' Right word

         Msg = "The first word is " & LWord & ","

         Msg = Msg & " the second word is " & RWord & "."

 Else

         Msg = "You did not enter two words."

 End If

 MsgBox Msg

End Sub