when looking for a single char, instr seems to miss the occurance if the char occurs as the first or last position in the string.

i have a work around, just repeat the first and last terms in the string, or insert a pad space.

But why is this nessesary?


VB Code:
  1. Public Function InStrW(ByRef LookIn As String, ByRef LookFor As String) As Boolean   ' break up lookfor into words, compares each
  2.  
  3. Dim arWS() As String
  4. Dim xx As Long
  5. Dim match As Boolean
  6. match = True
  7.  
  8. arWS = Split(Trim(LookFor), " ")
  9.  
  10. For xx = 0 To UBound(arWS) - 2
  11.         If InStr(LookIn, Trim(arWS(xx))) = 0 Then
  12.                 match = False
  13.         Else
  14.             Debug.Print "InstrW = True", (arWS(xx)) & "<", Str(xx), arWS(xx) & "<", "instr return: " & Str(InStr(LookIn, Trim(arWS(xx)))), LookIn, vbTab, LookFor
  15.             Debug.Print Trim(arWS(xx))
  16.            
  17.                 match = True
  18.                  InStrW = True
  19.                 xx = UBound(arWS) - 2
  20.                 Exit For
  21.         End If  'term in string?
  22. Next xx
  23. InStrW = match
  24.  
  25. End Function

(i am subtracting 2 due to the pad space i had to use)