StringBuilder.ToString 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
將 a StringBuilderString的值轉換為 。
多載
| 名稱 | Description |
|---|---|
| ToString() |
將此實例 String的值轉換為 。 |
| ToString(Int32, Int32) |
將該實例 String的子字串值轉換為 。 |
ToString()
將此實例 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.
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 成物件 String ,才能將該 StringBuilder 物件所代表的字串傳給有參數 String 的方法,或在使用者介面中顯示該參數。
適用於
ToString(Int32, Int32)
將該實例 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
子字串的長度。
傳回
一個值與該實例指定子串相同的字串。
例外狀況
備註
你必須呼叫 ToString 該方法將物件轉換 StringBuilder 成物件 String ,才能將該 StringBuilder 物件所代表的字串傳給有參數 String 的方法,或在使用者介面中顯示該參數。