Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


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

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)
    Else
        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.

 

 

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