TextSelection.ReplacePattern أسلوب

استبدال نص مطابق طوال كامل مستند نصي.

مساحة الاسم:  EnvDTE
التجميع:  EnvDTE (في EnvDTE.dll)

بناء الجملة

'إقرار
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

المعلمات

  • Pattern
    النوع: System.String
    مطلوبة.السلسلة المطلوب البحث عنها.
  • Replace
    النوع: System.String
    مطلوبة.نص إلى تستبدل كل حدوث ل Pattern.
  • vsFindOptionsValue
    النوع: System.Int32
    اختياري.vsFindOptionsثابت يشير إلى سلوك ReplacePattern، مثل كيفية بحث، ومكان لبدء بحث، ما إذا كنت تريد بحث إعادة توجيه مكالمة أو إلى الخلف، و حالة تحسس الأحرف.
  • Tags
    النوع: EnvDTE.TextRanges%
    اختياري.TextRangesمجموعة.إذا كان النقش نص متطابق هو تعبير عادي وتحتوي على subexpressions ذات العلامات، ثم Tagsيحتوي على مجموعة من EditPointالكائنات، واحد لكل subexpression ذات العلامات.

القيمة المُرجعة

النوع: System.Boolean
قيمة منطقية

ملاحظات

ReplacePattern for the TextDocument object replaces text like ReplacePattern for the TextSelection object, but it operates on the whole text document rather than just the selected text.

ReplacePatternأسلوب Visual Studioهو غير متوافق مع الإصدارات السابقة من ReplacePatternالأسلوب، سبب التعابير النظامية الآن بناء جملة مختلف.

أمثلة

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.

راجع أيضًَا

المرجع

TextSelection واجهة

TextSelection الأعضاء

EnvDTE مساحة الاسم

موارد أخرى

كيفية: الترجمة وإعادة تشغيل أمثلة التعليمات البرمجية لطراز كائن التنفيذ التلقائي