Right (function)

<< Click to Display Table of Contents >>

Right (function)

Right(String, n)

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

See also: Len, Left, Mid

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