語言

Utf8Formatter.TryFormat 方法

定義

多載

名稱 Description
TryFormat(Boolean, Span<Byte>, Int32, StandardFormat)

將 a Boolean 格式化為 UTF8 字串。

TryFormat(Byte, Span<Byte>, Int32, StandardFormat)

將 a Byte 格式化為 UTF8 字串。

TryFormat(DateTime, Span<Byte>, Int32, StandardFormat)

將 a DateTime 格式化為 UTF8 字串。

TryFormat(DateTimeOffset, Span<Byte>, Int32, StandardFormat)

將 a DateTimeOffset 格式化為 UTF8 字串。

TryFormat(Decimal, Span<Byte>, Int32, StandardFormat)

將 a Decimal 格式化為 UTF8 字串。

TryFormat(Double, Span<Byte>, Int32, StandardFormat)

將 a Double 格式化為 UTF8 字串。

TryFormat(Guid, Span<Byte>, Int32, StandardFormat)

將 a Guid 格式化為 UTF8 字串。

TryFormat(Int16, Span<Byte>, Int32, StandardFormat)

格式化 a Int16 為 UTF8 字串。

TryFormat(Int32, Span<Byte>, Int32, StandardFormat)

格式化 a Int32 為 UTF8 字串。

TryFormat(Int64, Span<Byte>, Int32, StandardFormat)

格式化 a Int64 為 UTF8 字串。

TryFormat(SByte, Span<Byte>, Int32, StandardFormat)

格式化 a SByte 為 UTF8 字串。

TryFormat(Single, Span<Byte>, Int32, StandardFormat)

將 a Single 格式化為 UTF8 字串。

TryFormat(TimeSpan, Span<Byte>, Int32, StandardFormat)

將 a TimeSpan 格式化為 UTF8 字串。

TryFormat(UInt16, Span<Byte>, Int32, StandardFormat)

將 a UInt16 格式化為 UTF8 字串。

TryFormat(UInt32, Span<Byte>, Int32, StandardFormat)

將 a UInt32 格式化為 UTF8 字串。

TryFormat(UInt64, Span<Byte>, Int32, StandardFormat)

將 a UInt64 格式化為 UTF8 字串。

TryFormat(Boolean, Span<Byte>, Int32, StandardFormat)

來源:
Utf8Formatter.Boolean.cs
來源:
Utf8Formatter.Boolean.cs
來源:
Utf8Formatter.Boolean.cs
來源:
Utf8Formatter.Boolean.cs
來源:
Utf8Formatter.Boolean.cs

將 a Boolean 格式化為 UTF8 字串。

public static bool TryFormat(bool value, Span<byte> destination, out int bytesWritten, System.Buffers.StandardFormat format = default);
static member TryFormat : bool * Span<byte> * int * System.Buffers.StandardFormat -> bool
Public Shared Function TryFormat (value As Boolean, destination As Span(Of Byte), ByRef bytesWritten As Integer, Optional format As StandardFormat = Nothing) As Boolean

參數

value
Boolean

要格式化的值。

destination
Span<Byte>

用來寫入 UTF8 格式值的緩衝區。

bytesWritten
Int32

當方法回傳時,包含格式化後文字的長度(位元組)。

format
StandardFormat

標準格式。

傳回

true 如果格式化操作成功; falsedestination 太小了。

備註

支援的格式:

格式字串 範例結果字串
G(預設) 正確/錯誤
l true/false

若方法失敗,則反覆增加緩衝區大小並重試直到成功。

適用於

TryFormat(Byte, Span<Byte>, Int32, StandardFormat)

來源:
Utf8Formatter.Integer.cs
來源:
Utf8Formatter.Integer.cs
來源:
Utf8Formatter.Integer.cs
來源:
Utf8Formatter.Integer.cs
來源:
Utf8Formatter.Integer.cs

將 a Byte 格式化為 UTF8 字串。

public static bool TryFormat(byte value, Span<byte> destination, out int bytesWritten, System.Buffers.StandardFormat format = default);
static member TryFormat : byte * Span<byte> * int * System.Buffers.StandardFormat -> bool
Public Shared Function TryFormat (value As Byte, destination As Span(Of Byte), ByRef bytesWritten As Integer, Optional format As StandardFormat = Nothing) As Boolean

參數

value
Byte

要格式化的值。

destination
Span<Byte>

用來寫入 UTF8 格式值的緩衝區。

bytesWritten
Int32

當方法回傳時,包含格式化後文字的長度(位元組)。

format
StandardFormat

標準格式。

傳回

true 如果格式化操作成功; falsedestination 太小了。

備註

支援的格式:

格式字串 範例結果字串
G/g(預設)
D/d 122
不/n 122
X/x 7a

若方法失敗,則反覆增加緩衝區大小並重試直到成功。

適用於

TryFormat(DateTime, Span<Byte>, Int32, StandardFormat)

來源:
Utf8Formatter.Date.cs
來源:
Utf8Formatter.Date.cs
來源:
Utf8Formatter.Date.cs
來源:
Utf8Formatter.Date.cs
來源:
Utf8Formatter.Date.cs

將 a DateTime 格式化為 UTF8 字串。

public static bool TryFormat(DateTime value, Span<byte> destination, out int bytesWritten, System.Buffers.StandardFormat format = default);
static member TryFormat : DateTime * Span<byte> * int * System.Buffers.StandardFormat -> bool
Public Shared Function TryFormat (value As DateTime, destination As Span(Of Byte), ByRef bytesWritten As Integer, Optional format As StandardFormat = Nothing) As Boolean

參數

value
DateTime

要格式化的值。

destination
Span<Byte>

用來寫入 UTF8 格式值的緩衝區。

bytesWritten
Int32

當方法回傳時,包含格式化後文字的長度(位元組)。

format
StandardFormat

標準格式。

傳回

true 如果格式化操作成功; falsedestination 太小了。

備註

支援的格式:

格式字串 範例結果字串 註解
G(預設) 05/25/2017 10:30:15
R 2017年1月3日 星期二 08:08:05 GMT (RFC 1123)
l 2017年1月3日 星期二 08:08:05 GMT (小寫 RFC 1123)
O 2017-06-12T05:30:45.7680000-07:00 (可往返)

若方法失敗,則反覆增加緩衝區大小並重試直到成功。

適用於

TryFormat(DateTimeOffset, Span<Byte>, Int32, StandardFormat)

來源:
Utf8Formatter.Date.cs
來源:
Utf8Formatter.Date.cs
來源:
Utf8Formatter.Date.cs
來源:
Utf8Formatter.Date.cs
來源:
Utf8Formatter.Date.cs

將 a DateTimeOffset 格式化為 UTF8 字串。

public static bool TryFormat(DateTimeOffset value, Span<byte> destination, out int bytesWritten, System.Buffers.StandardFormat format = default);
static member TryFormat : DateTimeOffset * Span<byte> * int * System.Buffers.StandardFormat -> bool
Public Shared Function TryFormat (value As DateTimeOffset, destination As Span(Of Byte), ByRef bytesWritten As Integer, Optional format As StandardFormat = Nothing) As Boolean

參數

value
DateTimeOffset

要格式化的值。

destination
Span<Byte>

用來寫入 UTF8 格式值的緩衝區。

bytesWritten
Int32

當方法回傳時,包含格式化後文字的長度(位元組)。

format
StandardFormat

標準格式。

傳回

true 如果格式化操作成功; falsedestination 太小了。

適用於

TryFormat(Decimal, Span<Byte>, Int32, StandardFormat)

來源:
Utf8Formatter.Decimal.cs
來源:
Utf8Formatter.Decimal.cs
來源:
Utf8Formatter.Decimal.cs
來源:
Utf8Formatter.Decimal.cs
來源:
Utf8Formatter.Decimal.cs

將 a Decimal 格式化為 UTF8 字串。

public static bool TryFormat(decimal value, Span<byte> destination, out int bytesWritten, System.Buffers.StandardFormat format = default);
static member TryFormat : decimal * Span<byte> * int * System.Buffers.StandardFormat -> bool
Public Shared Function TryFormat (value As Decimal, destination As Span(Of Byte), ByRef bytesWritten As Integer, Optional format As StandardFormat = Nothing) As Boolean

參數

value
Decimal

要格式化的值。

destination
Span<Byte>

用來寫入 UTF8 格式值的緩衝區。

bytesWritten
Int32

當方法回傳時,包含格式化後文字的長度(位元組)。

format
StandardFormat

標準格式。

傳回

true 如果格式化操作成功; falsedestination 太小了。

備註

支援的格式:

格式字串 範例結果字串 註解
G/g(預設)
女/女 12.45 固定點
E/e 1.245000e1 指數

若方法失敗,則反覆增加緩衝區大小並重試直到成功。

適用於

TryFormat(Double, Span<Byte>, Int32, StandardFormat)

來源:
Utf8Formatter.Float.cs
來源:
Utf8Formatter.Float.cs
來源:
Utf8Formatter.Float.cs
來源:
Utf8Formatter.Float.cs
來源:
Utf8Formatter.Float.cs

將 a Double 格式化為 UTF8 字串。

public static bool TryFormat(double value, Span<byte> destination, out int bytesWritten, System.Buffers.StandardFormat format = default);
static member TryFormat : double * Span<byte> * int * System.Buffers.StandardFormat -> bool
Public Shared Function TryFormat (value As Double, destination As Span(Of Byte), ByRef bytesWritten As Integer, Optional format As StandardFormat = Nothing) As Boolean

參數

value
Double

要格式化的值。

destination
Span<Byte>

用來寫入 UTF8 格式值的緩衝區。

bytesWritten
Int32

當方法回傳時,包含格式化後文字的長度(位元組)。

format
StandardFormat

標準格式。

傳回

true 如果格式化操作成功; falsedestination 太小了。

備註

支援的格式:

格式字串 範例結果字串 註解
G/g(預設)
女/女 12.45 固定點
E/e 1.245000e1 指數

若方法失敗,則反覆增加緩衝區大小並重試直到成功。

適用於

TryFormat(Guid, Span<Byte>, Int32, StandardFormat)

來源:
Utf8Formatter.Guid.cs
來源:
Utf8Formatter.Guid.cs
來源:
Utf8Formatter.Guid.cs
來源:
Utf8Formatter.Guid.cs
來源:
Utf8Formatter.Guid.cs

將 a Guid 格式化為 UTF8 字串。

public static bool TryFormat(Guid value, Span<byte> destination, out int bytesWritten, System.Buffers.StandardFormat format = default);
static member TryFormat : Guid * Span<byte> * int * System.Buffers.StandardFormat -> bool
Public Shared Function TryFormat (value As Guid, destination As Span(Of Byte), ByRef bytesWritten As Integer, Optional format As StandardFormat = Nothing) As Boolean

參數

value
Guid

要格式化的值。

destination
Span<Byte>

用來寫入 UTF8 格式值的緩衝區。

bytesWritten
Int32

當方法回傳時,包含格式化後文字的長度(位元組)。

format
StandardFormat

標準格式。

傳回

true 如果格式化操作成功; falsedestination 太小了。

備註

支援的格式:

格式字串 結果字串
D(預設) 嗯嗯
B {嗯嗯
P (嗯嗯
N 嗯嗯嗯

若方法失敗,則反覆增加緩衝區大小並重試直到成功。

適用於

TryFormat(Int16, Span<Byte>, Int32, StandardFormat)

來源:
Utf8Formatter.Integer.cs
來源:
Utf8Formatter.Integer.cs
來源:
Utf8Formatter.Integer.cs
來源:
Utf8Formatter.Integer.cs
來源:
Utf8Formatter.Integer.cs

格式化 a Int16 為 UTF8 字串。

public static bool TryFormat(short value, Span<byte> destination, out int bytesWritten, System.Buffers.StandardFormat format = default);
static member TryFormat : int16 * Span<byte> * int * System.Buffers.StandardFormat -> bool
Public Shared Function TryFormat (value As Short, destination As Span(Of Byte), ByRef bytesWritten As Integer, Optional format As StandardFormat = Nothing) As Boolean

參數

value
Int16

要格式化的值。

destination
Span<Byte>

用來寫入 UTF8 格式值的緩衝區。

bytesWritten
Int32

當方法回傳時,包含格式化後文字的長度(位元組)。

format
StandardFormat

標準格式。

傳回

true 如果格式化操作成功; falsedestination 太小了。

備註

支援的格式:

格式字串 範例結果字串
G/g(預設)
D/d 32767
不/n 32,767
X/x 7fff

若方法失敗,則反覆增加緩衝區大小並重試直到成功。

適用於

TryFormat(Int32, Span<Byte>, Int32, StandardFormat)

來源:
Utf8Formatter.Integer.cs
來源:
Utf8Formatter.Integer.cs
來源:
Utf8Formatter.Integer.cs
來源:
Utf8Formatter.Integer.cs
來源:
Utf8Formatter.Integer.cs

格式化 a Int32 為 UTF8 字串。

public static bool TryFormat(int value, Span<byte> destination, out int bytesWritten, System.Buffers.StandardFormat format = default);
static member TryFormat : int * Span<byte> * int * System.Buffers.StandardFormat -> bool
Public Shared Function TryFormat (value As Integer, destination As Span(Of Byte), ByRef bytesWritten As Integer, Optional format As StandardFormat = Nothing) As Boolean

參數

value
Int32

要格式化的值。

destination
Span<Byte>

用來寫入 UTF8 格式值的緩衝區。

bytesWritten
Int32

當方法回傳時,包含格式化後文字的長度(位元組)。

format
StandardFormat

標準格式。

傳回

true 如果格式化操作成功; falsedestination 太小了。

備註

支援的格式:

格式字串 範例結果字串
G/g(預設)
D/d 32767
不/n 32,767
X/x 7fff

若方法失敗,則反覆增加緩衝區大小並重試直到成功。

適用於

TryFormat(Int64, Span<Byte>, Int32, StandardFormat)

來源:
Utf8Formatter.Integer.cs
來源:
Utf8Formatter.Integer.cs
來源:
Utf8Formatter.Integer.cs
來源:
Utf8Formatter.Integer.cs
來源:
Utf8Formatter.Integer.cs

格式化 a Int64 為 UTF8 字串。

public static bool TryFormat(long value, Span<byte> destination, out int bytesWritten, System.Buffers.StandardFormat format = default);
static member TryFormat : int64 * Span<byte> * int * System.Buffers.StandardFormat -> bool
Public Shared Function TryFormat (value As Long, destination As Span(Of Byte), ByRef bytesWritten As Integer, Optional format As StandardFormat = Nothing) As Boolean

參數

value
Int64

要格式化的值。

destination
Span<Byte>

用來寫入 UTF8 格式值的緩衝區。

bytesWritten
Int32

當方法回傳時,包含格式化後文字的長度(位元組)。

format
StandardFormat

標準格式。

傳回

true 如果格式化操作成功; falsedestination 太小了。

備註

支援的格式:

格式字串 範例結果字串
G/g(預設)
D/d 32767
不/n 32,767
X/x 7fff

若方法失敗,則反覆增加緩衝區大小並重試直到成功。

適用於

TryFormat(SByte, Span<Byte>, Int32, StandardFormat)

來源:
Utf8Formatter.Integer.cs
來源:
Utf8Formatter.Integer.cs
來源:
Utf8Formatter.Integer.cs
來源:
Utf8Formatter.Integer.cs
來源:
Utf8Formatter.Integer.cs

重要

此 API 不符合 CLS 規範。

格式化 a SByte 為 UTF8 字串。

[System.CLSCompliant(false)]
public static bool TryFormat(sbyte value, Span<byte> destination, out int bytesWritten, System.Buffers.StandardFormat format = default);
[<System.CLSCompliant(false)>]
static member TryFormat : sbyte * Span<byte> * int * System.Buffers.StandardFormat -> bool
Public Shared Function TryFormat (value As SByte, destination As Span(Of Byte), ByRef bytesWritten As Integer, Optional format As StandardFormat = Nothing) As Boolean

參數

value
SByte

要格式化的值。

destination
Span<Byte>

用來寫入 UTF8 格式值的緩衝區。

bytesWritten
Int32

當方法回傳時,包含格式化後文字的長度(位元組)。

format
StandardFormat

標準格式。

傳回

true 如果格式化操作成功; falsedestination 太小了。

屬性

備註

支援的格式:

格式字串 範例結果字串
G/g(預設)
D/d 122
不/n 122
X/x 7a

若方法失敗,則反覆增加緩衝區大小並重試直到成功。

適用於

TryFormat(Single, Span<Byte>, Int32, StandardFormat)

來源:
Utf8Formatter.Float.cs
來源:
Utf8Formatter.Float.cs
來源:
Utf8Formatter.Float.cs
來源:
Utf8Formatter.Float.cs
來源:
Utf8Formatter.Float.cs

將 a Single 格式化為 UTF8 字串。

public static bool TryFormat(float value, Span<byte> destination, out int bytesWritten, System.Buffers.StandardFormat format = default);
static member TryFormat : single * Span<byte> * int * System.Buffers.StandardFormat -> bool
Public Shared Function TryFormat (value As Single, destination As Span(Of Byte), ByRef bytesWritten As Integer, Optional format As StandardFormat = Nothing) As Boolean

參數

value
Single

要格式化的值。

destination
Span<Byte>

用來寫入 UTF8 格式值的緩衝區。

bytesWritten
Int32

當方法回傳時,包含格式化後文字的長度(位元組)。

format
StandardFormat

標準格式。

傳回

true 如果格式化操作成功; falsedestination 太小了。

備註

支援的格式:

格式字串 範例結果字串 註解
G/g(預設)
女/女 12.45 固定點
E/e 1.245000e1 指數

若方法失敗,則反覆增加緩衝區大小並重試直到成功。

適用於

TryFormat(TimeSpan, Span<Byte>, Int32, StandardFormat)

來源:
Utf8Formatter.TimeSpan.cs
來源:
Utf8Formatter.TimeSpan.cs
來源:
Utf8Formatter.TimeSpan.cs
來源:
Utf8Formatter.TimeSpan.cs
來源:
Utf8Formatter.TimeSpan.cs

將 a TimeSpan 格式化為 UTF8 字串。

public static bool TryFormat(TimeSpan value, Span<byte> destination, out int bytesWritten, System.Buffers.StandardFormat format = default);
static member TryFormat : TimeSpan * Span<byte> * int * System.Buffers.StandardFormat -> bool
Public Shared Function TryFormat (value As TimeSpan, destination As Span(Of Byte), ByRef bytesWritten As Integer, Optional format As StandardFormat = Nothing) As Boolean

參數

value
TimeSpan

要格式化的值。

destination
Span<Byte>

用來寫入 UTF8 格式值的緩衝區。

bytesWritten
Int32

當方法回傳時,包含格式化後文字的長度(位元組)。

format
StandardFormat

標準格式。

傳回

true 如果格式化操作成功; falsedestination 太小了。

備註

支援的格式:

格式字串 結果字串 註解
c/t/T(預設) [-][d.]hh:mm:ss[.fffffff] (固定格式)
G [-]d:hh:mm:ss.ffffffff (一般長篇)
g [-][d:][h]h:mm:ss[.f[f[f[f[f]]]]]] (一般短篇)

若方法失敗,則反覆增加緩衝區大小並重試直到成功。

適用於

TryFormat(UInt16, Span<Byte>, Int32, StandardFormat)

來源:
Utf8Formatter.Integer.cs
來源:
Utf8Formatter.Integer.cs
來源:
Utf8Formatter.Integer.cs
來源:
Utf8Formatter.Integer.cs
來源:
Utf8Formatter.Integer.cs

重要

此 API 不符合 CLS 規範。

將 a UInt16 格式化為 UTF8 字串。

[System.CLSCompliant(false)]
public static bool TryFormat(ushort value, Span<byte> destination, out int bytesWritten, System.Buffers.StandardFormat format = default);
[<System.CLSCompliant(false)>]
static member TryFormat : uint16 * Span<byte> * int * System.Buffers.StandardFormat -> bool
Public Shared Function TryFormat (value As UShort, destination As Span(Of Byte), ByRef bytesWritten As Integer, Optional format As StandardFormat = Nothing) As Boolean

參數

value
UInt16

要格式化的值。

destination
Span<Byte>

用來寫入 UTF8 格式值的緩衝區。

bytesWritten
Int32

當方法回傳時,包含格式化後文字的長度(位元組)。

format
StandardFormat

標準格式。

傳回

true 如果格式化操作成功; falsedestination 太小了。

屬性

備註

支援的格式:

格式字串 範例結果字串
G/g(預設)
D/d 32767
不/n 32,767
X/x 7fff

若方法失敗,則反覆增加緩衝區大小並重試直到成功。

適用於

TryFormat(UInt32, Span<Byte>, Int32, StandardFormat)

來源:
Utf8Formatter.Integer.cs
來源:
Utf8Formatter.Integer.cs
來源:
Utf8Formatter.Integer.cs
來源:
Utf8Formatter.Integer.cs
來源:
Utf8Formatter.Integer.cs

重要

此 API 不符合 CLS 規範。

將 a UInt32 格式化為 UTF8 字串。

[System.CLSCompliant(false)]
public static bool TryFormat(uint value, Span<byte> destination, out int bytesWritten, System.Buffers.StandardFormat format = default);
[<System.CLSCompliant(false)>]
static member TryFormat : uint32 * Span<byte> * int * System.Buffers.StandardFormat -> bool
Public Shared Function TryFormat (value As UInteger, destination As Span(Of Byte), ByRef bytesWritten As Integer, Optional format As StandardFormat = Nothing) As Boolean

參數

value
UInt32

要格式化的值。

destination
Span<Byte>

用來寫入 UTF8 格式值的緩衝區。

bytesWritten
Int32

當方法回傳時,包含格式化後文字的長度(位元組)。

format
StandardFormat

標準格式。

傳回

true 如果格式化操作成功; falsedestination 太小了。

屬性

備註

支援的格式:

格式字串 範例結果字串
G/g(預設)
D/d 32767
不/n 32,767
X/x 7fff

若方法失敗,則反覆增加緩衝區大小並重試直到成功。

適用於

TryFormat(UInt64, Span<Byte>, Int32, StandardFormat)

來源:
Utf8Formatter.Integer.cs
來源:
Utf8Formatter.Integer.cs
來源:
Utf8Formatter.Integer.cs
來源:
Utf8Formatter.Integer.cs
來源:
Utf8Formatter.Integer.cs

重要

此 API 不符合 CLS 規範。

將 a UInt64 格式化為 UTF8 字串。

[System.CLSCompliant(false)]
public static bool TryFormat(ulong value, Span<byte> destination, out int bytesWritten, System.Buffers.StandardFormat format = default);
[<System.CLSCompliant(false)>]
static member TryFormat : uint64 * Span<byte> * int * System.Buffers.StandardFormat -> bool
Public Shared Function TryFormat (value As ULong, destination As Span(Of Byte), ByRef bytesWritten As Integer, Optional format As StandardFormat = Nothing) As Boolean

參數

value
UInt64

要格式化的值。

destination
Span<Byte>

用來寫入 UTF8 格式值的緩衝區。

bytesWritten
Int32

當方法回傳時,包含格式化後文字的長度(位元組)。

format
StandardFormat

標準格式。

傳回

true 如果格式化操作成功; falsedestination 太小了。

屬性

備註

支援的格式:

格式字串 範例結果字串
G/g(預設)
D/d 32767
不/n 32,767
X/x 7fff

若方法失敗,則反覆增加緩衝區大小並重試直到成功。

適用於