TextSelection::FindPattern Method (String^, Int32, TextRanges^)

 

Searches for the given pattern from the active point to the end of the document.

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

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

Parameters

Pattern
Type: System::String^

Required. The text to find.

vsFindOptionsValue
Type: System::Int32

One of the vsFindOptions values.

Tags
Type: EnvDTE::TextRanges^

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

Return Value

Type: System::Boolean

A Boolean value indicating true if the pattern is found, false if not.

FindPattern searches for the given text pattern from the edit point to the end of the document. One of the flags controls whether or not 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 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.

Sub FindPatternExample()
   ' Before running this example, open a text document.
   Dim objSel As TextSelection = DTE.ActiveDocument.Selection

   ' Advance to the next Visual Basic function beginning or end by 
   ' searching for  "Sub" with white space before and after it.
   If objSel.FindPattern(":WhSub:Wh", vsFindOptions.vsFindOptionsRegularExpression) Then
      ' Select the entire line.
      objSel.SelectLine()
   End If
End Sub
Return to top
Show: