devxlogo

A More Enhanced Right() Function

A More Enhanced Right() Function

Normally, the Right() Function VB returns only the Length specified from the End. If you want to extract the Right portion from any index of the String you have to play with the Mid() Function. It’s very tedious to write a Mid() function for each of the above functionalities. The solution is to use the following function to extract the right portion of the string from any specified position.

 Private Function MidR(strSource As String, StartIndex As Integer, LengthAs Integer)Dim StartPositon As Integer    If StartIndex > Len(strSource) Then StartIndex = Len(strSource)    StartPositon = StartIndex - Length + 1    If StartPositon > 0 Then        MidR = Mid(strSource, StartPositon, Length)    Else        MidR = Mid(strSource, 1, StartIndex)    End IfEnd FunctionUsage: StrValue=MidR("123456",5,2)Returns : 45

See also  Why ChatGPT Is So Important Today
devxblackblue

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist