RevInStr

By | 2002-06-01

Visual Basic 6 has a new function called InStrRev, which searches a string from right to left. I found it very usefeul, so much so that a project of mine relies completely on it. When I tried to work on the project at another location on VB5 I found that the function did not exist. So, I wrote it.
I left out the compare method, you can add it if you want

Original Author: Shane Presley

Inputs

RevInStr(String1 As String, String2 As String)

Assumptions


Example:
let positon = RevInStr(“Http://www.mypage.com/”,”/”)
In this case position would be 22, not 1

Returns

The Integer returned is the postion of the String 2 in String 1.

API Declarations

None

Code

Public Function RevInStr(String1 As String, String2 As String) As Integer
  Dim pos As Integer
  Dim pos2 As Integer
  
  Let pos2 = Len(String1)
  Do
    Let pos = (InStr(pos2, String1, String2))
    Let pos2 = pos2 - 1
  Loop Until pos > 0 Or pos2 = 0
  Let RevInStr = pos
End Function

Author: dwirch

Derek Wirch is a seasoned IT professional with an impressive career dating back to 1986. He brings a wealth of knowledge and hands-on experience that is invaluable to those embarking on their journey in the tech industry.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.