다음을 통해 공유


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
    형식: String

    필수 요소. 찾을 문자열입니다.

  • Replace
    형식: String

    필수 요소. Pattern과 일치하는 각 텍스트를 대체할 텍스트입니다.

  • vsFindOptionsValue
    형식: Int32

    선택적 요소. 검색 방법, 검색 시작 위치, 검색 방향(앞으로 또는 뒤로), 대/소문자 구분 등 ReplacePattern의 동작을 나타내는 vsFindOptions 상수입니다.

  • Tags
    형식: EnvDTE.TextRanges%

    선택적 요소. TextRanges 컬렉션입니다. 일치하는 텍스트 패턴이 태그가 지정된 부분식을 포함하는 정규식이면 Tags는 태그가 지정된 각 부분식에 대한 EditPoint 개체의 컬렉션을 포함합니다.

반환 값

형식: Boolean
부울 값입니다.

설명

ReplacePattern에 TextDocument 개체와 마찬가지로 텍스트를 대체 ReplacePattern 에 TextSelection 선택한 텍스트 뿐만 아니라 전체 텍스트 문서에서 작동 하는 개체입니다.

이번 버전에서는 정규식에 사용되는 구문이 다르므로 Visual Studio의 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 보안

참고 항목

참조

TextSelection 인터페이스

EnvDTE 네임스페이스

기타 리소스

방법: 자동화 개체 모델 코드의 예제 컴파일 및 실행