Using the Equivalent of Right Function in VB.NET


As VB.NET no longer supports the handy Right Function anymore, the sweet old days of using this Right function in VB6 programmings are already over. However, you can use the equivalent function code that i have created below. I have named the function as sRight since Right conflicts with another function in VB.NET. Just copy and paste this simple codes at the bottom of your project module or form.



'---Copy and Paste this piece of code into your module or project

Public Function sRight( ByVal iString As String, ByVal Position as Integer) As String
Return Mid(iString,(len(iString)+1) - Position , Position)
End Function



Now, for instance, we have a string "Spaceship" stored in a variable myStr


'--- Variable Declarations
Dim myStr As String
Dim Output as String

myStr = "Spaceship" '--- Store the word Spaceship into myStr
Output = sRight(myStr,4) '---call sRight function to retrieve the last 4 letters of the string
Msgbox(Output) '--- Display a messagebox



The output from the message above will be "ship"


See also Left Function in VB.NET
See also Mid Function in VB.NET

See also Left Function in VB6/Classic
See also Mid Function in VB6/Classic
See also Right Function in VB6/Classic

0 comments