home *** CD-ROM | disk | FTP | other *** search
- // RINSTR.SCP - Function to return the index of the last occurence of a substring in a string.
- // Similar to the Instr function
- // Copyright (c) 2000, Vector Networks Limited
- // All Rights Reserved
- //
- // Revision History:
- // 5.3 19-Jul-00 AB - Created.
- // 7.0 04-Feb-02 DB - Updated to handle arithmetic changes in v7.0.
-
- Function RInStr (Strng as String, SubStr as String) as Integer
- Dim Pos as Integer, TPos as Integer, Str as String, SLen, SSLen
-
- Pos = 0
- TPos = 0
- SLen = Len (Strng)
-
- // If the string supplied is not empty, continue.
-
- If SLen != 0 then
- // Print "Searching for right-most occurrence of: ", SubStr, " in: ", Strng
-
- // Get the length of SubStr
-
- SSLen = Len (SubStr)
-
- // Work backwards through the string until the substring is found.
-
- For Pos = SLen - SSLen + 1 to 1 step 1
- Str = Mid (Strng, Pos, SSLen)
- // Print "Test string: ", Str, " at position: ", Pos, " of ", SLen
- If (Str = SubStr) then
- // Print "Substring: ", SubStr, " located at position: ", Pos
- TPos = Pos
- Exit For
- Endif
- Next
- Endif
-
- // When the substring is found, the loop is exited and the value of TPos returned.
-
- RInStr = TPos
- // Print "Returning: ", TPos
- End Function