RIGHT |
RIGHT(string, length) |
Returns a substring from the right of a string (Variant / String). |
string | The text string (String). |
length | The number of characters to return (Long). |
REMARKS |
* If "string" is Null, then Null is returned. * If "length" = 0, then a zero length string ("") is returned. * If "length" > Len("string"), then "string" is returned. * You can use the LEFT function to return a number of characters from the left of a string. * You can use the LEN function to return the number of characters in a string. * You can use the INSTR function to return the position of a substring within a larger string, starting at the beginning. * You can use the INSTRREV function to return the position of a substring within a larger string, starting at the end. * You can use the MID Function to return a substring from the middle, left or right of a string. * You can use the RIGHTB function that can be used with byte data. * You can use the RIGHT$ function to return a String data type instead of a Variant data type. * You can use the RIGHTB$ function to return a String data type instead of a Variant data type. * You can use the RTRIM function to return a string without trailing spaces. * The equivalent Excel function is Application.WorksheetFunction.RIGHT * The equivalent .NET function is Microsoft.VisualBasic.Strings.Right * For the Microsoft documentation refer to learn.microsoft.com |
Debug.Print Right("sometext", 4) '= "text"
Debug.Print Right("sometext", 20) '= "sometext"
Debug.Print Right("", 6) '= ""
Dim sResult As String
sResult = Right("bettersolutions", 9)
Debug.Print sResult '= "solutions"
Dim sText As String
sText = "bettersolutions.com"
sResult = Right(sText, Len(sText) - 6)) 'remove the first 6 characters
Debug.Print sResult '= "solutions.com"
sText = "better solutions com"
sResult = Right(sText, InStrRev(sText, " ") + 1) 'returns the last word
Debug.Print sResult '= "com"
© 2024 Better Solutions Limited. All Rights Reserved. © 2024 Better Solutions Limited Top