Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All
Important This document may not represent best practices for current development, links to downloads and other resources may no longer be valid. Current recommended version can be found here.

TextSelection.FindPattern Method

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

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

bool FindPattern (
	[InAttribute] string Pattern,
	[OptionalAttribute] [InAttribute] int vsFindOptionsValue,
	[OptionalAttribute] [InAttribute] out TextRanges Tags
)
boolean FindPattern (
	/** @attribute InAttribute() */ String Pattern, 
	/** @attribute InAttribute() */ /** @attribute OptionalAttribute() */ int vsFindOptionsValue, 
	/** @attribute InAttribute() */ /** @attribute OutAttribute() */ /** @attribute OptionalAttribute() */ /** @ref */ TextRanges Tags
)
JScript does not support passing value-type arguments by reference.

Parameters

Pattern

Required. The text to find.

vsFindOptionsValue

One of the vsFindOptions values.

Tags

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

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 an end point 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.

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

Community Additions

ADD
Show:
© 2015 Microsoft