次の方法で共有


TextDocument.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
    型 : String

    必須。 検索する文字列。

  • Replace
    型 : String

    必須。 Pattern の各出現箇所を置換するテキスト。

  • vsFindOptionsValue
    型 : Int32

    省略可能。 検索方法、検索の開始位置、検索方向、大文字と小文字の区別など、ReplacePattern の動作を示す vsFindOptions 定数。

  • Tags
    型 : EnvDTE.TextRanges%

    省略可能。 TextRanges コレクション。 一致するテキスト パターンがタグ付き部分式を含む正規表現の場合、Tags には、EditPoint オブジェクト (各タグ付き部分式に 1 つ) のコレクションが含まれます。

戻り値

型 : Boolean
ブール値。

解説

TextDocument オブジェクトの ReplacePattern は、TextSelection オブジェクトの ReplacePattern と同様にテキストを置換しますが、選択したテキストだけでなく、テキスト ドキュメント全体を処理します。

Visual Studio 2005 の ReplacePattern メソッドと、旧バージョンの 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 セキュリティ

  • 直前の呼び出し元に対する完全な信頼。このメンバーは、部分的に信頼されているコードから使用することはできません。詳細については、「部分信頼コードからのライブラリの使用」を参照してください。

参照

関連項目

TextDocument インターフェイス

EnvDTE 名前空間

その他の技術情報

方法 : オートメーション オブジェクト モデルのコード例をコンパイルおよび実行する