Condividi tramite


TextSelection.FindPattern(String, Int32, TextRanges) Method

Definition

Searches for the given pattern from the active point to the end of the document. This API has been deprecated in VS 2022 and above. Please refer the breaking API changes in VS 2022 for guidance on how to migrate API usage via modern find and repalce APIs.

public:
 bool FindPattern(System::String ^ Pattern, int vsFindOptionsValue, [Runtime::InteropServices::Out] EnvDTE::TextRanges ^ % Tags);
[System.Runtime.InteropServices.DispId(30)]
public bool FindPattern (string Pattern, int vsFindOptionsValue = 0, out EnvDTE.TextRanges Tags = default);
[System.Runtime.InteropServices.DispId(30)]
public bool FindPattern (string Pattern, int vsFindOptionsValue, out EnvDTE.TextRanges Tags);
[<System.Runtime.InteropServices.DispId(30)>]
abstract member FindPattern : string * int * TextRanges -> bool
Public Function FindPattern (Pattern As String, Optional vsFindOptionsValue As Integer = 0, Optional ByRef Tags As TextRanges = Nothing) As Boolean
Public Function FindPattern (Pattern As String, vsFindOptionsValue As Integer, ByRef Tags As TextRanges) As Boolean

Parameters

Pattern
String

Required. The text to find.

vsFindOptionsValue
Int32

One of the vsFindOptions values.

Tags
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.

Returns

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

Attributes

Examples

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  

Remarks

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.

Applies to