ITextBuffer.Replace Method

Replaces a sequence of characters with different text. This is equivalent to first deleting the text to be replaced and then inserting the new text.

Namespace:  Microsoft.VisualStudio.Text
Assembly:  Microsoft.VisualStudio.Text.Data (in Microsoft.VisualStudio.Text.Data.dll)


Function Replace ( _
    replaceSpan As Span, _
    replaceWith As String _
) As ITextSnapshot
ITextSnapshot Replace(
    Span replaceSpan,
    string replaceWith
ITextSnapshot^ Replace(
    Span replaceSpan, 
    String^ replaceWith
abstract Replace : 
        replaceSpan:Span * 
        replaceWith:string -> ITextSnapshot 
function Replace(
    replaceSpan : Span, 
    replaceWith : String
) : ITextSnapshot


  • replaceWith
    Type: System.String
    The new text to replace the old.

Return Value

Type: Microsoft.VisualStudio.Text.ITextSnapshot
The ITextSnapshot.


Exception Condition

replaceWith is nulla null reference (Nothing in Visual Basic).


A text edit is currently active.


replaceSpan.End is greater than the length of the buffer.


This is a shortcut for creating a new ITextEdit object, using it to replace the text, and then applying it. If the replacement fails on account of a read-only region, the snapshot returned will be the same as the current snapshot of the buffer before the attempted replacement.

.NET Framework Security

See Also


ITextBuffer Interface

Microsoft.VisualStudio.Text Namespace