StringBuilder.ToString 方法

定義

StringBuilder 的值轉換為 String

多載

ToString()

將這個執行個體的值轉換為 String

ToString(Int32, Int32)

將這個執行個體的子字串值轉換為 String

ToString()

Source:
StringBuilder.cs
Source:
StringBuilder.cs
Source:
StringBuilder.cs

將這個執行個體的值轉換為 String

public:
 override System::String ^ ToString();
public override string ToString ();
override this.ToString : unit -> string
Public Overrides Function ToString () As String

傳回

其值和這個執行個體相同的字串。

範例

下列程式碼範例示範如何呼叫 ToString 方法。 這個範例是提供給 類別之較大範例的 StringBuilder 一部分。

// Display the number of characters in the StringBuilder
// and its string.
Console::WriteLine("{0} chars: {1}", sb->Length, sb->ToString());
// Display the number of characters in the StringBuilder and its string.
Console.WriteLine("{0} chars: {1}", sb.Length, sb.ToString());
// Display the number of characters in the StringBuilder and its string.
printfn $"{sb.Length} chars: {sb}"
' Display the number of characters in the StringBuilder and its string.
Console.WriteLine("{0} chars: {1}", sb.Length, sb.ToString())

備註

您必須先呼叫 ToString 方法,才能 StringBuilder 將 物件 StringStringBuilder 代表的字串傳遞至具有 String 參數的方法,或在使用者介面中顯示該物件。

適用於

ToString(Int32, Int32)

Source:
StringBuilder.cs
Source:
StringBuilder.cs
Source:
StringBuilder.cs

將這個執行個體的子字串值轉換為 String

public:
 System::String ^ ToString(int startIndex, int length);
public string ToString (int startIndex, int length);
override this.ToString : int * int -> string
Public Function ToString (startIndex As Integer, length As Integer) As String

參數

startIndex
Int32

這個執行個體中的子字串開始位置。

length
Int32

子字串的長度。

傳回

字串,此字串值與這個執行個體的指定子字串值相同。

例外狀況

startIndexlength 小於零。

-或-

startIndexlength 總計大於目前執行個體的長度。

備註

您必須先呼叫 ToString 方法,才能 StringBuilder 將 物件 StringStringBuilder 代表的字串傳遞至具有 String 參數的方法,或在使用者介面中顯示該物件。

適用於