Sdílet prostřednictvím


TextSelection.ReplacePattern – metoda

Porovnávání textu dokumentu celý text nahradí.

Obor názvů:  EnvDTE
Sestavení:  EnvDTE (v EnvDTE.dll)

Syntaxe

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

Parametry

  • Replace
    Typ: System.String
    Povinné.Nahradit všechny výskyty textu Pattern.
  • vsFindOptionsValue
    Typ: System.Int32
    Nepovinné.A vsFindOptions Konstanta určující chování ReplacePattern, například vyhledávání, kde začít hledání, zda se má hledat dopředu nebo dozadu a citlivost případu.
  • Tags
    Typ: EnvDTE.TextRanges%
    Nepovinné.A TextRanges kolekce.Pokud vzorek odpovídající text regulární výraz a potom obsahuje tagované podvýrazy Tags obsahuje kolekci EditPoint objektů pro jednotlivé tagované dílčím.

Vrácená hodnota

Typ: System.Boolean
Logická hodnota.

Poznámky

ReplacePatternpro TextDocument objektu nahradí text jako ReplacePattern pro TextSelection objektu, ale pracuje celý text dokumentu, nikoli pouze na vybraný text.

ReplacePattern Metodu pro Visual Studio není kompatibilní se staršími verzemi ReplacePattern Metoda, protože regulární výrazy mají nyní jinou syntaxi.

Příklady

Sub ReplacePatternExample(dte As DTE)

    ' Create a new text file and insert 10 lines of text.
    dte.ItemOperations.NewFile()
    Dim txtSel As TextSelection = _
        CType(dte.ActiveDocument.Selection, TextSelection)
    Dim txtDoc As TextDocument = _
        CType(dte.ActiveDocument.Object(), TextDocument)
    Dim editPnt As EditPoint = txtDoc.StartPoint.CreateEditPoint()
    Dim i As Integer
    For i = 1 To 10
        editPnt.Insert("This is a test." & vbCrLf)
    Next i

    If MsgBox("Replace 'test' with 'done deal'?", vbYesNo) = _
        MsgBoxResult.Yes Then
        txtSel.SelectAll()
        txtSel.ReplacePattern("test", "done deal")
    End If

End Sub
public void ReplacePatternExample(DTE dte)
{
    // Create a new text file and insert 10 lines of text.
    dte.ItemOperations.NewFile(@"General\Text File", "", 
        Constants.vsViewKindPrimary);
    TextSelection txtSel = (TextSelection)dte.ActiveDocument.Selection;
    TextDocument txtDoc = (TextDocument)dte.ActiveDocument.Object("");
    EditPoint editPnt = txtDoc.StartPoint.CreateEditPoint();
    for (int i = 1; i <= 10; i++)
    {
        editPnt.Insert("This is a test." + Environment.NewLine);
    }

    if (MessageBox.Show("Replace 'test' with 'done deal'?", "", 
        MessageBoxButtons.YesNo) == DialogResult.Yes)
    {
        TextRanges dummy = null;
        txtSel.SelectAll();
        txtSel.ReplacePattern("test", "done deal", 
            (int)vsFindOptions.vsFindOptionsNone, ref dummy);
    }
}

Zabezpečení rozhraní .NET Framework

Viz také

Odkaz

TextSelection Rozhraní

EnvDTE – obor názvů

Další zdroje

How to: Compile and Run the Automation Object Model Code Examples