Compartilhar via


Source.SetText Method

Definition

Puts the specified text into the source file.

Overloads

SetText(String)

Replaces the source contents with the given text.

SetText(TextSpan, String)

Replaces the specified span of source with the given text.

SetText(Int32, Int32, Int32, Int32, String)

Replaces the specified section of source with the given text.

Remarks

These methods change the text in the source file, either by replacing the entire contents of the source or only a specified section.

SetText(String)

Replaces the source contents with the given text.

public:
 void SetText(System::String ^ newText);
public:
 void SetText(Platform::String ^ newText);
void SetText(std::wstring const & newText);
public void SetText (string newText);
member this.SetText : string -> unit
Public Sub SetText (newText As String)

Parameters

newText
String

The new text.

Remarks

This method calls the GetLastLineIndex method to get the last line and then calls the ReplaceLines method to replace all lines with the new text.

This method can throw an exception if there was an error.

Applies to

SetText(TextSpan, String)

Replaces the specified span of source with the given text.

public:
 void SetText(Microsoft::VisualStudio::TextManager::Interop::TextSpan span, System::String ^ newText);
public:
 void SetText(Microsoft::VisualStudio::TextManager::Interop::TextSpan span, Platform::String ^ newText);
void SetText(Microsoft::VisualStudio::TextManager::Interop::TextSpan span, std::wstring const & newText);
public void SetText (Microsoft.VisualStudio.TextManager.Interop.TextSpan span, string newText);
member this.SetText : Microsoft.VisualStudio.TextManager.Interop.TextSpan * string -> unit
Public Sub SetText (span As TextSpan, newText As String)

Parameters

span
TextSpan

A TextSpan object describing the span to replace.

newText
String

A string holding the new text.

Remarks

This method forwards the call to the other span-oriented SetText(Int32, Int32, Int32, Int32, String) method.

Applies to

SetText(Int32, Int32, Int32, Int32, String)

Replaces the specified section of source with the given text.

public:
 void SetText(int startLine, int startCol, int endLine, int endCol, System::String ^ newText);
public:
 void SetText(int startLine, int startCol, int endLine, int endCol, Platform::String ^ newText);
void SetText(int startLine, int startCol, int endLine, int endCol, std::wstring const & newText);
public void SetText (int startLine, int startCol, int endLine, int endCol, string newText);
member this.SetText : int * int * int * int * string -> unit
Public Sub SetText (startLine As Integer, startCol As Integer, endLine As Integer, endCol As Integer, newText As String)

Parameters

startLine
Int32

The first line of source to replace.

startCol
Int32

The beginning offset of the first character on the first line to replace.

endLine
Int32

The last line of source to replace.

endCol
Int32

The last character offset on the last line to replace.

newText
String

The new text.

Remarks

This method validates the input range, then calls the ReplaceLines method to replace the specified section with the new text.

If newText is a null value, then the given span is deleted.

This method can throw an exception if there was an error.

Applies to