Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
C# Helper...
 
XML RSS Feed
Follow VBHelper on Twitter
 
 
MSDN Visual Basic Community
 
 
 
 
 
TitleIteratively find the last occurrance of a substring without using InStrRev
KeywordsInStrRev, last occurrance
CategoriesStrings
 
InStrRev does this in VB6 but in previous versions of VB you needed to use your own function similar to this one. (Yes it is a bit odd that this example is saved in VB6 format but is only needed in versions before VB6. Copy and paste the function's code if you use an earlier version. Use InStrRev in VB6.)

This function repeatedly searches the string for the substring. It returns the index of the last occurrance it finds.

 
Public Function FindLast(ByVal source As String, ByVal _
    target As String, Optional start_at As Integer = 1) As _
    Integer
Dim pos As Integer

    ' Assume we won't find it.
    FindLast = 0

    ' Search for the target.
    pos = InStr(start_at, source, target)
    Do While pos > 0
        FindLast = pos
        pos = InStr(pos + 1, source, target)
    Loop
End Function
 
 
Copyright © 1997-2010 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated