Visual Basic Language Reference  

Right Function

Returns a string containing a specified number of characters from the right side of a string.

Public Shared Function Right( _
   ByVal Str As String, _
   ByVal Length As Integer _
) As String

Parameters

Str
Required. String expression from which the rightmost characters are returned.
Length
Required. Integer. Numeric expression indicating how many characters to return. If 0, a zero-length string ("") is returned. If greater than or equal to the number of characters in Str, the entire string is returned.

Exceptions/Errors

Exception type Error number Condition
ArgumentException 5 Length < 0.

Remarks

To determine the number of characters in Str, use the Len function. If used in a Windows Form, or any other class that has a Right property, you must fully qualify the function with Microsoft.VisualBasic.Right.

Example

This example demonstrates the use of the Right function to return a substring of a given String. In a class that has a Right property, it may be necessary to fully qualify the Right function.

Dim myString As String = "Hello World!"
Dim subString As String
subString = Microsoft.VisualBasic.Right(myString, 6)   ' Returns "World!"

See Also

Left Function | Len Function | Mid Function | ArgumentException