EditPoint2.ReplacePattern Method

Finds a pattern in the specified range of text and replaces it with the specified text.

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

Syntax

'Declaration
Function ReplacePattern ( _
    Point As TextPoint, _
    Pattern As String, _
    Replace As String, _
    vsFindOptionsValue As Integer, _
    <OutAttribute> ByRef Tags As TextRanges _
) As Boolean
bool ReplacePattern(
    TextPoint Point,
    string Pattern,
    string Replace,
    int vsFindOptionsValue,
    out TextRanges Tags
)
bool ReplacePattern(
    [InAttribute] TextPoint^ Point, 
    [InAttribute] String^ Pattern, 
    [InAttribute] String^ Replace, 
    [InAttribute] int vsFindOptionsValue, 
    [InAttribute] [OutAttribute] TextRanges^% Tags
)
abstract ReplacePattern : 
        Point:TextPoint * 
        Pattern:string * 
        Replace:string * 
        vsFindOptionsValue:int * 
        Tags:TextRanges byref -> bool
function ReplacePattern(
    Point : TextPoint, 
    Pattern : String, 
    Replace : String, 
    vsFindOptionsValue : int, 
    Tags : TextRanges
) : boolean

Parameters

  • Point
    Type: EnvDTE.TextPoint

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

  • Pattern
    Type: String

    Required. The string to find.

  • Replace
    Type: String

    Required. The replacement string for Pattern.

  • vsFindOptionsValue
    Type: Int32

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

  • Tags
    Type: EnvDTE.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 sub-expression.

Return Value

Type: Boolean
true if replacement occurs successfully; otherwise, false.

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 TextDocument.ReplacePattern. The Tags collection returns only information for the last matched pattern.

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

.NET Framework Security

See Also

Reference

EditPoint2 Interface

EnvDTE80 Namespace