This documentation is archived and is not being maintained.

FindPattern Method

Visual Studio .NET 2003

Finds a given matching pattern in the selected text.

[Visual Basic .NET]
Public Function FindPattern( _
   ByVal Pattern As String, _
   Optional ByVal Flags As Integer = 0, _
   Optional ByRef EndPoint As EditPoint = Nothing, _
   Optional ByRef Tags As TextRanges = Nothing _
) As Boolean
[Visual Basic 6]
Function FindPattern( _
   ByVal Pattern As String, _
   Optional ByVal Flags As Int = 0, _
   Optional ByRef EndPoint As EditPoint = Nothing, _
   Optional ByRef Tags As TextRanges = Nothing _
) As Boolean
[C++]
HRESULT __stdcall FindPattern(
   BSTR Pattern,
   int Flags,
   EditPoint** EndPoint,
   TextRanges** Tags,
   /* [out, retval] */ VARIANT_BOOL* retVal
);
[C#]
public bool FindPattern(
   string Pattern,
   int Flags,
   ref EditPoint EndPoint,
   ref TextRanges Tags
);
[JScript .NET]
public function FindPattern(
   Pattern : String,
   Flags : int,
   EndPoint : EditPoint,
   Tags : TextRanges
) : Boolean

Parameters

Pattern
Required. The text you want to find.
Flags
Optional. A vsFindOptions constant indicating the type of search to perform:
EndPoint
Optional. An EditPoint object representing the point that is to be moved to the end of the matched pattern.
Tags
Optional. If the matched pattern is a regular expression containing tagged sub-expressions, then the Tags argument contains a collection of TextRange objects, one for each tagged subexpression.

Return Value

Returns True if the pattern is found, False if not.

Remarks

FindPattern searches for the given text pattern from the edit point to the end of the document. One of the flags controls whether the search starts at the beginning of the document. The pattern may be a regular or other expression. The return value indicates whether the pattern is found. If the pattern is found, the edit point is moved to the beginning of the match. Otherwise, the edit location is unchanged.

If an endpoint is supplied and the pattern found, then FindPattern moves the endpoint to the end of the found pattern.

If the matched pattern is a regular expression and contains tagged subexpressions, then the Tags argument returns a collection of TextRange objects, one for each tagged subexpression.

Example

Sub FindPatternExample()
   Dim objTextDoc As TextDocument
   Dim objEditPt As EditPoint, iCtr As Integer
        
   'Create a new text file.
   DTE.ItemOperations.NewFile("General\Text File")
       
   'Get a handle to the new document and create an EditPoint.
   objTextDoc = DTE.ActiveDocument.Object("TextDocument")
   objEditPt = objTextDoc.StartPoint.CreateEditPoint
        
   'Insert ten lines of text.
   For iCtr = 1 To 10
      objeditpt.Insert("This is a test." & Chr(13))
   Next iCtr
   objEditPt.StartOfDocument()
   'Search for the word "test."
   If objeditpt.FindPattern("test") = True Then
      msgbox("Found the word.")
   End If
End Sub

See Also

Applies To: EditPoint Object

Show: