home *** CD-ROM | disk | FTP | other *** search
/ Chip 2004 April / CMCD0404.ISO / Software / Demo / PCDUO / data1.cab / Script_Samples / RINSTR.SCP < prev    next >
Encoding:
Text File  |  2003-11-28  |  1.2 KB  |  43 lines

  1. // RINSTR.SCP - Function to return the index of the last occurence of a substring in a string.
  2. // Similar to the Instr function
  3. // Copyright (c) 2000, Vector Networks Limited
  4. // All Rights Reserved
  5. //
  6. // Revision History:
  7. // 5.3 19-Jul-00 AB - Created.
  8. // 7.0 04-Feb-02 DB - Updated to handle arithmetic changes in v7.0.
  9.  
  10. Function RInStr (Strng as String, SubStr as String) as Integer
  11.   Dim Pos as Integer, TPos as Integer, Str as String, SLen, SSLen
  12.  
  13.   Pos = 0
  14.   TPos = 0
  15.   SLen = Len (Strng)
  16.  
  17.   // If the string supplied is not empty, continue.
  18.  
  19.   If SLen != 0 then
  20. //  Print "Searching for right-most occurrence of: ", SubStr, " in: ", Strng
  21.  
  22.     // Get the length of SubStr
  23.  
  24.     SSLen = Len (SubStr)
  25.  
  26.     // Work backwards through the string until the substring is found.
  27.  
  28.     For Pos = SLen - SSLen + 1 to 1 step 1
  29.       Str = Mid (Strng, Pos, SSLen)
  30. //   Print "Test string: ", Str, " at position: ", Pos, " of ", SLen
  31.       If (Str = SubStr) then 
  32. //      Print "Substring: ", SubStr, " located at position: ", Pos
  33.         TPos = Pos
  34.         Exit For
  35.       Endif
  36.     Next
  37.   Endif
  38.  
  39.   // When the substring is found, the loop is exited and the value of TPos returned.
  40.  
  41.   RInStr = TPos
  42. //  Print "Returning: ", TPos
  43. End Function