Home > Language Reference > Classes > StringMatcher

InStr Method

Carries out a search in the specified string.

Syntax

Public Function InStr(ByVal lStart As Long, ByRef sText As String, Optional ByRef lLength As Long = 0) As Long
Public Function InStr(ByVal
lStart As Long, ByRef sText As StreamMemory, Optional ByRef lLength As Long = 0) As Long

ParameterDescription
lStartSearch start position.
sTextText in which the pattern is search.
lLengthReturns the lenght of the pattern recognized.

Remarks

The InStr function finds the pattern previously set by the SetPattern method or the SetRegExp method in the specified text, and returns the position of the first character recognized. The text can be provided either in a string or in a StreamMemory object.

The sText parameter specifies the string in which to carry out the search while the lStart parameter specifies where to begin searching in this string. The lLength parameter, if specified, is set by the function to the length of the recognized pattern. This last parameter is useful for counting the number of occurences found like in the example below:

Public Sub FindAll(ByRef sMatcher as StringMatcher, ByRef sString as String)
  Dim i as Integer, n as Integer

  i=1
  Do
    i=sMatcher.InStr(i,sString,n)
    If i=0 Then Exit Do
    MsgBox "Found : " & Mid(sString,i,n)
    i = i + n
  Loop
End Sub

If using the StreamMemory flavor of the function, the return value and the lStart parameter are zero-based indexed while if using the string flavor, the return value and the lStart parameter are one-based indexed.

The StringMatcher introduction page gives a full example about using this object and its methods.

System requirements

SystemMinimal versionRemarks
Palm OSPalm OS 3.0N/A