Compartir a través de


TextSelection.ReplacePattern (Método)

Reemplaza el texto coincidente en todo el documento de texto.

Espacio de nombres:  EnvDTE
Ensamblado:  EnvDTE (en EnvDTE.dll)

Sintaxis

'Declaración
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

Parámetros

  • Pattern
    Tipo: System.String
    Obligatorio.Cadena que se va a buscar.
  • Replace
    Tipo: System.String
    Obligatorio.El texto que reemplazará cada aparición de Pattern.
  • vsFindOptionsValue
    Tipo: System.Int32
    Opcional.Una constante vsFindOptions que indica el comportamiento de ReplacePattern, como la forma de buscar, dónde comenzar la búsqueda, si se buscará hacia delante o hacia atrás, y la distinción entre mayúsculas y minúsculas.
  • Tags
    Tipo: EnvDTE.TextRanges%
    Opcional.Colección de TextRanges.Si el modelo de texto coincidente es una expresión regular y contiene subexpresiones etiquetadas, el parámetro Tags contendrá una colección de objetos EditPoint, uno por cada subexpresión etiquetada.

Valor devuelto

Tipo: System.Boolean
Valor booleano.

Comentarios

ReplacePattern para el objeto TextDocument reemplaza el texto como ReplacePattern para el objeto TextSelection, pero funciona en todo el documento de texto, en lugar de funcionar simplemente en el texto seleccionado.

El método ReplacePattern para Visual Studio es incompatible con versiones anteriores del método ReplacePattern, ya que las expresiones regulares tienen ahora una sintaxis diferente.

Ejemplos

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

Seguridad de .NET Framework

Vea también

Referencia

TextSelection Interfaz

EnvDTE (Espacio de nombres)

Otros recursos

Cómo: Compilar y ejecutar los ejemplos de código del modelo de objetos de automatización