Aracılığıyla paylaş


TextSelection.ReplacePattern Yöntem

Boyunca tüm metin belgesi metin eşleştirme değiştirir.

Ad alanı:  EnvDTE
Derleme:  EnvDTE (EnvDTE.dll içinde)

Sözdizimi

'Bildirim
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

Parametreler

  • Replace
    Tür: System.String
    Gerekli.Her geçtiği yerde değiştirmek için metin Pattern.
  • vsFindOptionsValue
    Tür: System.Int32
    İsteğe Bağlı.A vsFindOptions davranışı gösteren sabit ReplacePattern, arama, arama başlamak nereye, ileriye veya geriye doğru ara verip ve gibi büyük/küçük harf duyarlılığı.
  • Tags
    Tür: EnvDTE.TextRanges%
    İsteğe Bağlı.A TextRanges koleksiyonu.Eşleşen metin örüntüsünün normal bir ifadedir ve etiketli taşıyıcının sonra varsa Tags topluluğu içeren EditPoint nesneleri, tek etiketli bir alt ifadeyi her.

Dönüş Değeri

Tür: System.Boolean
Bir Boole değeri.

Açıklamalar

ReplacePatterniçin TextDocument nesneyi değiştirir gibi metin ReplacePattern için TextSelection nesnesi, ancak çalışır tam metin belge yerine seçili metni yeterlidir.

ReplacePattern Yöntemi Visual Studio önceki sürümleriyle uyumlu olmayan ReplacePattern yöntemi, normal ifadeler şimdi farklı bir sözdizimi. çünkü

Örnekler

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);
    }
}

.NET Framework Güvenliği

Ayrıca bkz.

Başvuru

TextSelection Arabirim

EnvDTE Ad Alanı

Diğer Kaynaklar

Nasıl Yapılır: derlemek ve otomasyon nesne modeli kod örnekleri çalıştırma