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

  1. // LINSTR.SCP - Function to return the index of the first occurence of a 
  2. // substring in a string. Replaces the Instr function.
  3. //
  4. // Copyright (c) 2002, Vector Networks Limited
  5. // All Rights Reserved
  6. //
  7. // Revision History:
  8. // 7.0 21-Mar-02 DB - Created, using RINSTR.SCP 20-Feb-02.
  9. //                    - Comment out debugging code.
  10.  
  11. //  Don't type loop counter variables. Just Dim them.
  12.  
  13. Function LInStr (Strng as String, SubStr as String) as Number
  14.   Dim Pos, TPos, Str as String, SLen, SSLen
  15.  
  16.   Pos = 0
  17.   TPos = 0
  18.   SLen = Len (Strng)
  19.  
  20.   // If the string supplied is not empty, continue.
  21.  
  22.   If SLen != 0 then
  23. //  Print "Searching for first occurrence of: ", SubStr, " in: ", Strng
  24.  
  25.     // Get the length of SubStr
  26.  
  27.     SSLen = Len (SubStr)
  28.  
  29.     // Work through the string until the substring is found.
  30.  
  31.     For Pos = 1 To SLen - SSLen
  32.       Str = Mid (Strng, Pos, SSLen)
  33. //    Print "Test string: ", Str, " at position: ", Pos, " of ", SLen
  34.       If (Str = SubStr) then 
  35. //      Print "Substring: ", SubStr, " located at position: ", Pos
  36.         TPos = Pos
  37.         Exit For
  38.       Endif
  39.     Next
  40.   Endif
  41.  
  42.   // When the substring is found, the loop is exited and the value of TPos returned.
  43.  
  44.   LInStr = TPos
  45. //  Print "Returning: ", TPos
  46. End Function
  47.