Browse DevX
Sign up for e-mail newsletters from DevX

Tip of the Day
Language: Visual Basic
Expertise: Beginner
Oct 8, 2001



Building the Right Environment to Support AI, Machine Learning and Deep Learning

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, Length
As 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)
        MidR = Mid(strSource, 1, StartIndex)
    End If
End Function

Usage: StrValue=MidR("123456",5,2)
Returns : 45
Prasad Haridass
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



Thanks for your registration, follow us on our social networks to keep up-to-date