Compartir a través de


EditPoint.FindPattern(String, Int32, EditPoint, TextRanges) Method

Definition

Finds a given matching pattern in the selected text. 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.

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

Parameters

Pattern
String

Required. The text you want to find.

vsFindOptionsValue
Int32

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

EndPoint
EditPoint

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

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

true if the pattern is found; otherwise, false.

Attributes

Examples

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  

Remarks

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 subexpressions, then the Tags argument returns a collection of TextRange objects, one for each tagged subexpression.

Applies to