다음을 통해 공유


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
    형식: System.String
    필수적 요소로서,찾을 문자열입니다.
  • Replace
    형식: System.String
    필수적 요소로서,Pattern과 일치하는 각 텍스트를 대체할 텍스트입니다.
  • vsFindOptionsValue
    형식: System.Int32
    선택적 요소로서,검색 방법, 검색 시작 위치, 검색 방향(앞으로 또는 뒤로), 대/소문자 구분 등 ReplacePattern의 동작을 나타내는 vsFindOptions 상수입니다.
  • Tags
    형식: EnvDTE.TextRanges%
    선택적 요소로서,TextRanges 컬렉션입니다.일치하는 텍스트 패턴이 태그가 지정된 부분식을 포함하는 정규식이면 Tags는 태그가 지정된 각 부분식에 대한 EditPoint 개체의 컬렉션을 포함합니다.

반환 값

형식: System.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 네임스페이스

기타 리소스

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