This documentation is archived and is not being maintained.

ReplaceText Method

Visual Studio .NET 2003

Replaces the selected text with the given text.

[Visual Basic .NET]
Public Sub ReplaceText( _
   ByVal PointOrCount As Object, _
   ByVal Text As String, _
   ByVal Flags As Integer _
[Visual Basic 6]
Sub ReplaceText( _
   ByVal PointOrCount As Variant, _
   ByVal Text As String, _
   ByVal Flags As Int _
HRESULT __stdcall ReplaceText(
   VARI   ANT PointOrCount,
   BSTR Text,
   int Flags
public void ReplaceText(
   object PointOrCount,
   string Text,
   int Flags
[JScript .NET]
public function ReplaceText(
   PointOrCount : Object,
   Text : String,
   Flags : int


Required. Either a TextPoint Object or an integer that determines the text to replace.
Required. The text to insert.
Required. A vsEPReplaceTextOptions constant representing an editor action.


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.


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
   ' 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

See Also

Applies To: EditPoint Object