EditPoint2::FindPattern Method (String^, Int32, EditPoint^, TextRanges^)

 

Finds a given matching pattern in the selected text.

Namespace:   EnvDTE80
Assembly:  EnvDTE80 (in EnvDTE80.dll)

bool FindPattern(
	String^ Pattern,
	int vsFindOptionsValue = 0,
	EditPoint^% EndPoint = null,
	TextRanges^% Tags = null
)

Parameters

Pattern
Type: System::String^

Required. The text you want to find.

vsFindOptionsValue
Type: System::Int32

Optional. A vsFindOptions constant indicating the type of search to perform. The vsFindOptionsMatchInHiddenText constant value does not apply to this method because FindPattern searches all text, including hidden text.

EndPoint
Type: EnvDTE::EditPoint^

Optional. An EditPoint object representing the point that is to be moved to the end of the matched pattern.

Tags
Type: EnvDTE::TextRanges^

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 sub-expression.

Return Value

Type: System::Boolean

true if the pattern is found; otherwise, false.

FindPattern searches all text (including hidden) for the given text pattern from the edit point to the end of the document. One flag 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 sub-expressions, then the Tags argument returns a collection of TextRange objects, one for each tagged sub-expression.

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
Return to top
Show: