Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Locate Last Character Occurrence in String..

Access Howto:

Locate Last Character Occurrence in String..

by  smedvid  Posted    (Edited  )
This looked like a good candidate for a FAQ!
===========================================
raskew (Programmer) Apr 1, 2002
Function xLastInStr(tstr As String, twhat As String) As Integer
'*******************************************
'Name: xLastInStr (Function)
'Purpose: Return location of last instance of a character or phrase.
'Inputs: Call xLastInStr("the quick brown fox jumped the lazy dog", "the")
'Output: 28 - Location of last occurence of "the"
'*******************************************

Dim i As Integer, n As Integer, tlen As Integer

n = 0
tlen = Len(twhat)
For i = Len(RTrim(tstr)) To 1 Step -1

If Mid(tstr, i, tlen) = twhat Then
n = i
Exit For
End If
Next i

xLastInStr = n

End Function
Register to rate this FAQ  : BAD 1 2 3 4 5 6 7 8 9 10 GOOD
Please Note: 1 is Bad, 10 is Good :-)

Part and Inventory Search

Back
Top