home *** CD-ROM | disk | FTP | other *** search
- // LINSTR.SCP - Function to return the index of the first occurence of a
- // substring in a string. Replaces the Instr function.
- //
- // Copyright (c) 2002, Vector Networks Limited
- // All Rights Reserved
- //
- // Revision History:
- // 7.0 21-Mar-02 DB - Created, using RINSTR.SCP 20-Feb-02.
- // - Comment out debugging code.
-
- // Don't type loop counter variables. Just Dim them.
-
- Function LInStr (Strng as String, SubStr as String) as Number
- Dim Pos, TPos, 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 first occurrence of: ", SubStr, " in: ", Strng
-
- // Get the length of SubStr
-
- SSLen = Len (SubStr)
-
- // Work through the string until the substring is found.
-
- For Pos = 1 To SLen - SSLen
- 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.
-
- LInStr = TPos
- // Print "Returning: ", TPos
- End Function
-