IUtf8SpanFormattable.TryFormat 方法

定義

嘗試將目前實例的值格式化為 UTF-8 到提供的位元組範圍。

public:
 bool TryFormat(Span<System::Byte> utf8Destination, [Runtime::InteropServices::Out] int % bytesWritten, ReadOnlySpan<char> format, IFormatProvider ^ provider);
public bool TryFormat (Span<byte> utf8Destination, out int bytesWritten, ReadOnlySpan<char> format, IFormatProvider? provider);
abstract member TryFormat : Span<byte> * int * ReadOnlySpan<char> * IFormatProvider -> bool
Public Function TryFormat (utf8Destination As Span(Of Byte), ByRef bytesWritten As Integer, format As ReadOnlySpan(Of Char), provider As IFormatProvider) As Boolean

參數

utf8Destination
Span<Byte>

要寫入這個實例值的範圍,其格式為位元組範圍。

bytesWritten
Int32

當這個方法傳回時,會包含以 utf8Destination 寫入的位元組數目。

format
ReadOnlySpan<Char>

包含字元的範圍,這些字元代表的標準或自訂格式字串能定義 utf8Destination 可接受的格式。

provider
IFormatProvider

選擇性物件,其可為 utf8Destination 提供特定的文化特性格式資訊。

傳回

若格式化成功則為 true,否則為 false

備註

這個介面的實作應該會產生與 實作相同的 字元 ToString(String, IFormatProvider) 字串,或在 TryFormat(Span<Char>, Int32, ReadOnlySpan<Char>, IFormatProvider) 相同類型上。 只有在目的地緩衝區中沒有足夠的空間時,TryFormat 才應該傳回;任何其他失敗都應該擲回 false 例外狀況。

適用於