Compartir a través de


EditPoint.ReplaceText(Object, String, Int32) Method

Definition

Replaces the selected text with the given text. This API has been deprecated in VS 2022 and above. Please refer the breaking API changes in VS 2022 for guidance on how to migrate API usage via modern find and repalce APIs.

public:
 void ReplaceText(System::Object ^ PointOrCount, System::String ^ Text, int Flags);
public:
 void ReplaceText(Platform::Object ^ PointOrCount, Platform::String ^ Text, int Flags);
void ReplaceText(winrt::Windows::Foundation::IInspectable const & PointOrCount, std::wstring const & Text, int Flags);
[System.Runtime.InteropServices.DispId(164)]
public void ReplaceText (object PointOrCount, string Text, int Flags);
[<System.Runtime.InteropServices.DispId(164)>]
abstract member ReplaceText : obj * string * int -> unit
Public Sub ReplaceText (PointOrCount As Object, Text As String, Flags As Integer)

Parameters

PointOrCount
Object

Required. Either a TextPoint object or an integer that determines the text to replace.

Text
String

Required. The text to insert.

Flags
Int32

Required. A vsEPReplaceTextOptions constant representing an editor action.

Attributes

Examples

Sub ReplaceTextExample()  
   Dim objTextDoc As TextDocument  
   Dim objMovePt As EditPoint  
   Dim objEditPt As EditPoint, iCtr As Integer  

   ' Create a new text file.  
   DTE.ItemOperations.NewFile("General\Text File")  

   ' Get a handle to the new document and create an EditPoint.  
   objTextDoc = DTE.ActiveDocument.Object("TextDocument")  
   objMovePt = objTextDoc.EndPoint.CreateEditPoint  
   objEditPt = objTextDoc.StartPoint.CreateEditPoint  

   ' Insert ten lines of text.  
   For iCtr = 1 To 10  
      objEditPt.Insert("This is a test." & Chr(13))  
   Next iCtr  
   objEditPt.StartOfDocument()  
   objMovePt.EndOfDocument()  
   ' Replace all occurrences of "test" with "thing."  
   MsgBox("Replacing all text with a new string...")  
   objEditPt.ReplaceText(objMovePt, "ALL TEXT REPLACED WITH THIS SENTENCE.", vsEPReplaceTextOptions.vsEPReplaceTextAutoformat)  
End Sub  

Remarks

ReplaceText replaces the text between the edit point and PointOrCount with Text, making an attempt to correctly preserve the locations of markers for breakpoints, named shortcuts, and so forth.

Applies to