StringBuilder.ToString StringBuilder.ToString StringBuilder.ToString StringBuilder.ToString Method

定義

StringBuilder 的值轉換為 StringConverts the value of a StringBuilder to a String.

多載

ToString() ToString() ToString() ToString()

將這個執行個體的值轉換為 StringConverts the value of this instance to a String.

ToString(Int32, Int32) ToString(Int32, Int32) ToString(Int32, Int32) ToString(Int32, Int32)

將這個執行個體的子字串值轉換為 StringConverts the value of a substring of this instance to a String.

ToString() ToString() ToString() ToString()

將這個執行個體的值轉換為 StringConverts the value of this instance to a String.

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

傳回

其值和這個執行個體相同的字串。A string whose value is the same as this instance.

範例

下列程式碼範例示範如何呼叫 ToString 方法。The following example demonstrates calling the ToString method. 這個範例是針對StringBuilder類別提供之較大範例的一部分。This example is part of a larger example provided for the StringBuilder class.

// 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.
Console.WriteLine("{0} chars: {1}", sb.Length, sb.ToString())

備註

您必須先呼叫ToString方法,將StringBuilder物件String轉換成物件,然後才能將StringBuilder物件所代表的字串傳遞給具有String參數的方法,或將它顯示在使用者介面中。You must call the ToString method to convert the StringBuilder object to a String object before you can pass the string represented by the StringBuilder object to a method that has a String parameter or display it in the user interface.

ToString(Int32, Int32) ToString(Int32, Int32) ToString(Int32, Int32) ToString(Int32, Int32)

將這個執行個體的子字串值轉換為 StringConverts the value of a substring of this instance to a 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 Int32 Int32 Int32

這個執行個體中的子字串開始位置。The starting position of the substring in this instance.

length
Int32 Int32 Int32 Int32

子字串的長度。The length of the substring.

傳回

字串,此字串值與這個執行個體的指定子字串值相同。A string whose value is the same as the specified substring of this instance.

例外狀況

startIndexlength 小於零。startIndex or length is less than zero.

-或--or- startIndexlength 總計大於目前執行個體的長度。The sum of startIndex and length is greater than the length of the current instance.

備註

您必須先呼叫ToString方法,將StringBuilder物件String轉換成物件,然後才能將StringBuilder物件所代表的字串傳遞給具有String參數的方法,或將它顯示在使用者介面中。You must call the ToString method to convert the StringBuilder object to a String object before you can pass the string represented by the StringBuilder object to a method that has a String parameter or display it in the user interface.

適用於