Condividi tramite


EditPoint.ReplacePattern(TextPoint, String, String, Int32, TextRanges) Method

Definition

Finds a pattern in the specified range of text and replaces it with the specified 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(152)]
public bool ReplacePattern (EnvDTE.TextPoint Point, string Pattern, string Replace, int vsFindOptionsValue = 0, out EnvDTE.TextRanges Tags = default);
[<System.Runtime.InteropServices.DispId(152)>]
abstract member ReplacePattern : EnvDTE.TextPoint * string * string * int * TextRanges -> bool
Public Function ReplacePattern (Point As TextPoint, Pattern As String, Replace As String, Optional vsFindOptionsValue As Integer = 0, Optional ByRef Tags As TextRanges = Nothing) As Boolean

Parameters

Point
TextPoint

Required. The endpoint of the specified range of text. The edit point and Point are the boundaries for replacement.

Pattern
String

Required. The string to find.

Replace
String

Required. The replacement string for Pattern.

vsFindOptionsValue
Int32

Optional. A vsFindOptions constant indicating the type of search to perform.

Tags
TextRanges

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

Returns

true if replacement occurs successfully; otherwise, false.

Attributes

Examples

Sub ReplacePatternExample()  
   Dim objTextDoc As TextDocument  
   Dim objMovePt As EditPoint  
   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")  
   objMovePt = objTextDoc.EndPoint.CreateEditPoint  
   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()  
   objMovePt.EndOfDocument()  
   ' Replace all occurrences of "test" with "thing."  
    objEditPt.ReplacePattern(objMovePt, "test", "thing", vsFindOptions.vsFindOptionsFromStart)  
End Sub  

Remarks

ReplacePattern finds text similarly to FindPattern, except that it only searches the text between edit point and the argument Point. To find and replace in the entire document, use ReplacePattern. The Tags collection returns only information for the last matched pattern.

Applies to