Metoda TextSelection.ReplacePattern —
Zastępuje dopasowywania tekstu w całym dokumencie cały tekst.
Przestrzeń nazw: EnvDTE
Zestaw: EnvDTE (w EnvDTE.dll)
Składnia
'Deklaracja
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
Parametry
Pattern
Typ: StringWymagany.Aby znaleźć ciąg.
Replace
Typ: StringWymagany.Tekst, który ma zamienić każde wystąpienie Pattern.
vsFindOptionsValue
Typ: Int32Opcjonalnie.A vsFindOptions stałą zachowanie ReplacePattern, na przykład sposobu wyszukiwania, gdzie ma się zaczynać wyszukiwanie, czy wyszukiwanie do przodu lub do tyłu i rozróżnianie wielkości liter.
Tags
Typ: EnvDTE.TextRanges%Opcjonalnie.Kolekcja TextRanges.Jeśli wzór dopasowany tekst jest to wyrażenie regularne i zawiera oznaczone browserCaps to Tags zawiera zbiór EditPoint obiektów, po jednym dla każdego z oznakowanych wyrażenia cząstkowego.
Wartość zwracana
Typ: Boolean
Wartość logiczna.
Uwagi
ReplacePatterndla TextDocument obiektu zastępuje tekst jak ReplacePattern dla TextSelection obiekt, ale działa na cały tekst dokumentu, a nie tylko zaznaczonego tekstu.
ReplacePattern Metodą Visual Studio jest niezgodny z wcześniejszymi wersjami programu ReplacePattern metoda, ponieważ już innej składni wyrażeń regularnych.
Przykłady
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);
}
}
Zabezpieczenia programu .NET Framework
- Pełne zaufanie do bezpośredniego wywołującego. Tego elementu członkowskiego nie można używać w kodzie częściowo zaufanym. Aby uzyskać więcej informacji, zobacz Używanie bibliotek pochodzących z częściowo zaufanego kodu.
Zobacz też
Informacje
Inne zasoby
Porady: kompilowanie i uruchamianie kodu modelu obiektów automatyzacji — przykłady