共用方式為


EditPoint2.ReplacePattern 方法

在指定的文字範圍中尋找比對模式,並以指定的文字取代它。

命名空間:  EnvDTE80
組件:  EnvDTE80 (在 EnvDTE80.dll 中)

語法

'宣告
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

參數

  • Point
    類型:TextPoint

    必要項。 所指定文字範圍的結束點。 編輯點和 Point 是取代的界限。

  • Pattern
    類型:String

    必要項。 要尋找的字串。

  • Replace
    類型:String

    必要項。 Pattern 的取代字串。

  • vsFindOptionsValue
    類型:Int32

    選擇項。 vsFindOptions 常數,表示要執行的搜尋類型。

  • Tags
    類型:TextRanges%

    選擇項。 如果符合的模式比對是規則運算式,並且含有標記子運算式,則 Tags 會針對每個標記子運算式包含一個 TextRange 物件的集合。

傳回值

類型:Boolean
如果取代成功,則為 true,否則為 false。

備註

ReplacePattern 尋找文字的方式與 FindPattern 類,不同的是前者只搜尋介於編輯點與 Point 引數之間的文字。 若要在整份文件中進行尋找和取代,請使用 TextDocument.ReplacePattern。 Tags 集合只傳回上一次符合模式比對的資訊。

範例

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 安全性

請參閱

參考

EditPoint2 介面

EnvDTE80 命名空間