Compartilhar via


Source.GetText Method

Definition

Gets text from the source file.

Overloads

GetText(TextSpan)

Gets the text included in the text span.

GetText(Int32, Int32, Int32, Int32)

Gets the text between the specified locations.

GetText()

Gets all of the text of the source file.

Remarks

These methods provide different ways of obtaining text from the source file.

GetText(TextSpan)

Gets the text included in the text span.

public:
 System::String ^ GetText(Microsoft::VisualStudio::TextManager::Interop::TextSpan span);
public:
 Platform::String ^ GetText(Microsoft::VisualStudio::TextManager::Interop::TextSpan span);
std::wstring GetText(Microsoft::VisualStudio::TextManager::Interop::TextSpan span);
public string GetText (Microsoft.VisualStudio.TextManager.Interop.TextSpan span);
member this.GetText : Microsoft.VisualStudio.TextManager.Interop.TextSpan -> string
Public Function GetText (span As TextSpan) As String

Parameters

span
TextSpan

A TextSpan structure, which defines a block of text.

Returns

The text included in the text span.

Applies to

GetText(Int32, Int32, Int32, Int32)

Gets the text between the specified locations.

public:
 System::String ^ GetText(int startLine, int startCol, int endLine, int endCol);
public:
 Platform::String ^ GetText(int startLine, int startCol, int endLine, int endCol);
std::wstring GetText(int startLine, int startCol, int endLine, int endCol);
public string GetText (int startLine, int startCol, int endLine, int endCol);
member this.GetText : int * int * int * int -> string
Public Function GetText (startLine As Integer, startCol As Integer, endLine As Integer, endCol As Integer) As String

Parameters

startLine
Int32

The first line of text to obtain.

startCol
Int32

The offset on the first line to the first character to obtain.

endLine
Int32

The last line of text to obtain.

endCol
Int32

The offset on the last line to the last character to obtain.

Returns

The desired text. This can be an empty string.

Remarks

This method forwards the call to the GetLineText method on the IVsTextLines object passed to the Source class constructor. This method throws an exception if GetLineText returns an error.

Applies to

GetText()

Gets all of the text of the source file.

public:
 System::String ^ GetText();
public:
 Platform::String ^ GetText();
std::wstring GetText();
public string GetText ();
member this.GetText : unit -> string
Public Function GetText () As String

Returns

The entire source file.

Remarks

Use this method to access the entire source file as a single block of text.

This method calls the GetLastLineIndex method on the IVsTextLines object passed to the Source class constructor, and then returns the result of calling GetText(Int32, Int32, Int32, Int32) with the start and ending location of the source file. This method throws an exception if GetLastLineIndex returns an error.

Applies to