Utf8Formatter.TryFormat Method

Definition

Overloads

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

Formats a Boolean as a UTF8 string.

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

Formats a Byte as a UTF8 string.

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

Formats a DateTime as a UTF8 string.

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

Formats a DateTimeOffset as a UTF8 string.

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

Formats a Decimal as a UTF8 string.

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

Formats a Double as a UTF8 string.

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

Formats a Guid as a UTF8 string.

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

Formats an Int16 as a UTF8 string.

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

Formats an Int32 as a UTF8 string.

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

Formats an Int64 as a UTF8 string.

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

Formats an SByte as a UTF8 string.

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

Formats a Single as a UTF8 string.

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

Formats a TimeSpan as a UTF8 string.

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

Formats a UInt16 as a UTF8 string.

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

Formats a UInt32 as a UTF8 string.

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

Formats a UInt64 as a UTF8 string.

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

Source:
Utf8Formatter.Boolean.cs
Source:
Utf8Formatter.Boolean.cs
Source:
Utf8Formatter.Boolean.cs

Formats a Boolean as a UTF8 string.

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

Parameters

value
Boolean

The value to format.

destination
Span<Byte>

The buffer to write the UTF8-formatted value to.

bytesWritten
Int32

When the method returns, contains the length of the formatted text in bytes.

format
StandardFormat

The standard format to use.

Returns

true if the formatting operation succeeds; false if destination is too small.

Remarks

Formats supported:

Format string Example result string
G (default) True/False
l true/false

If the method fails, iteratively increase the size of the buffer and retry until it succeeds.

Applies to

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

Source:
Utf8Formatter.Integer.cs
Source:
Utf8Formatter.Integer.cs
Source:
Utf8Formatter.Integer.cs

Formats a Byte as a UTF8 string.

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

Parameters

value
Byte

The value to format.

destination
Span<Byte>

The buffer to write the UTF8-formatted value to.

bytesWritten
Int32

When the method returns, contains the length of the formatted text in bytes.

format
StandardFormat

The standard format to use.

Returns

true if the formatting operation succeeds; false if destination is too small.

Remarks

Formats supported:

Format string Example result string
G/g (default)
D/d 122
N/n 122
X/x 7a

If the method fails, iteratively increase the size of the buffer and retry until it succeeds.

Applies to

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

Source:
Utf8Formatter.Date.cs
Source:
Utf8Formatter.Date.cs
Source:
Utf8Formatter.Date.cs

Formats a DateTime as a UTF8 string.

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

Parameters

value
DateTime

The value to format.

destination
Span<Byte>

The buffer to write the UTF8-formatted value to.

bytesWritten
Int32

When the method returns, contains the length of the formatted text in bytes.

format
StandardFormat

The standard format to use.

Returns

true if the formatting operation succeeds; false if destination is too small.

Remarks

Formats supported:

Format string Example result string Comments
G (default) 05/25/2017 10:30:15
R Tue, 03 Jan 2017 08:08:05 GMT (RFC 1123)
l tue, 03 jan 2017 08:08:05 gmt (Lowercase RFC 1123)
O 2017-06-12T05:30:45.7680000-07:00 (Round-trippable)

If the method fails, iteratively increase the size of the buffer and retry until it succeeds.

Applies to

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

Source:
Utf8Formatter.Date.cs
Source:
Utf8Formatter.Date.cs
Source:
Utf8Formatter.Date.cs

Formats a DateTimeOffset as a UTF8 string.

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

Parameters

value
DateTimeOffset

The value to format.

destination
Span<Byte>

The buffer to write the UTF8-formatted value to.

bytesWritten
Int32

When the method returns, contains the length of the formatted text in bytes.

format
StandardFormat

The standard format to use.

Returns

true if the formatting operation succeeds; false if destination is too small.

Applies to

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

Source:
Utf8Formatter.Decimal.cs
Source:
Utf8Formatter.Decimal.cs
Source:
Utf8Formatter.Decimal.cs

Formats a Decimal as a UTF8 string.

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

Parameters

value
Decimal

The value to format.

destination
Span<Byte>

The buffer to write the UTF8-formatted value to.

bytesWritten
Int32

When the method returns, contains the length of the formatted text in bytes.

format
StandardFormat

The standard format to use.

Returns

true if the formatting operation succeeds; false if destination is too small.

Remarks

Formats supported:

Format string Example result string Comments
G/g (default)
F/f 12.45 Fixed point
E/e 1.245000e1 Exponential

If the method fails, iteratively increase the size of the buffer and retry until it succeeds.

Applies to

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

Source:
Utf8Formatter.Float.cs
Source:
Utf8Formatter.Float.cs
Source:
Utf8Formatter.Float.cs

Formats a Double as a UTF8 string.

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

Parameters

value
Double

The value to format.

destination
Span<Byte>

The buffer to write the UTF8-formatted value to.

bytesWritten
Int32

When the method returns, contains the length of the formatted text in bytes.

format
StandardFormat

The standard format to use.

Returns

true if the formatting operation succeeds; false if destination is too small.

Remarks

Formats supported:

Format string Example result string Comments
G/g (default)
F/f 12.45 Fixed point
E/e 1.245000e1 Exponential

If the method fails, iteratively increase the size of the buffer and retry until it succeeds.

Applies to

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

Source:
Utf8Formatter.Guid.cs
Source:
Utf8Formatter.Guid.cs
Source:
Utf8Formatter.Guid.cs

Formats a Guid as a UTF8 string.

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

Parameters

value
Guid

The value to format.

destination
Span<Byte>

The buffer to write the UTF8-formatted value to.

bytesWritten
Int32

When the method returns, contains the length of the formatted text in bytes.

format
StandardFormat

The standard format to use.

Returns

true if the formatting operation succeeds; false if destination is too small.

Remarks

Formats supported:

Format string Result string
D (default) nnnnnnnn-nnnn-nnnn-nnnn-nnnnnnnnnnnn
B {nnnnnnnn-nnnn-nnnn-nnnn-nnnnnnnnnnnn}
P (nnnnnnnn-nnnn-nnnn-nnnn-nnnnnnnnnnnn)
N nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn

If the method fails, iteratively increase the size of the buffer and retry until it succeeds.

Applies to

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

Source:
Utf8Formatter.Integer.cs
Source:
Utf8Formatter.Integer.cs
Source:
Utf8Formatter.Integer.cs

Formats an Int16 as a UTF8 string.

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

Parameters

value
Int16

The value to format.

destination
Span<Byte>

The buffer to write the UTF8-formatted value to.

bytesWritten
Int32

When the method returns, contains the length of the formatted text in bytes.

format
StandardFormat

The standard format to use.

Returns

true if the formatting operation succeeds; false if destination is too small.

Remarks

Formats supported:

Format string Example result string
G/g (default)
D/d 32767
N/n 32,767
X/x 7fff

If the method fails, iteratively increase the size of the buffer and retry until it succeeds.

Applies to

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

Source:
Utf8Formatter.Integer.cs
Source:
Utf8Formatter.Integer.cs
Source:
Utf8Formatter.Integer.cs

Formats an Int32 as a UTF8 string.

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

Parameters

value
Int32

The value to format.

destination
Span<Byte>

The buffer to write the UTF8-formatted value to.

bytesWritten
Int32

When the method returns, contains the length of the formatted text in bytes.

format
StandardFormat

The standard format to use.

Returns

true if the formatting operation succeeds; false if destination is too small.

Remarks

Formats supported:

Format string Example result string
G/g (default)
D/d 32767
N/n 32,767
X/x 7fff

If the method fails, iteratively increase the size of the buffer and retry until it succeeds.

Applies to

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

Source:
Utf8Formatter.Integer.cs
Source:
Utf8Formatter.Integer.cs
Source:
Utf8Formatter.Integer.cs

Formats an Int64 as a UTF8 string.

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

Parameters

value
Int64

The value to format.

destination
Span<Byte>

The buffer to write the UTF8-formatted value to.

bytesWritten
Int32

When the method returns, contains the length of the formatted text in bytes.

format
StandardFormat

The standard format to use.

Returns

true if the formatting operation succeeds; false if destination is too small.

Remarks

Formats supported:

Format string Example result string
G/g (default)
D/d 32767
N/n 32,767
X/x 7fff

If the method fails, iteratively increase the size of the buffer and retry until it succeeds.

Applies to

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

Source:
Utf8Formatter.Integer.cs
Source:
Utf8Formatter.Integer.cs
Source:
Utf8Formatter.Integer.cs

Important

This API is not CLS-compliant.

Formats an SByte as a UTF8 string.

[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

Parameters

value
SByte

The value to format.

destination
Span<Byte>

The buffer to write the UTF8-formatted value to.

bytesWritten
Int32

When the method returns, contains the length of the formatted text in bytes.

format
StandardFormat

The standard format to use.

Returns

true if the formatting operation succeeds; false if destination is too small.

Attributes

Remarks

Formats supported:

Format string Example result string
G/g (default)
D/d 122
N/n 122
X/x 7a

If the method fails, iteratively increase the size of the buffer and retry until it succeeds.

Applies to

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

Source:
Utf8Formatter.Float.cs
Source:
Utf8Formatter.Float.cs
Source:
Utf8Formatter.Float.cs

Formats a Single as a UTF8 string.

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

Parameters

value
Single

The value to format.

destination
Span<Byte>

The buffer to write the UTF8-formatted value to.

bytesWritten
Int32

When the method returns, contains the length of the formatted text in bytes.

format
StandardFormat

The standard format to use.

Returns

true if the formatting operation succeeds; false if destination is too small.

Remarks

Formats supported:

Format string Example result string Comments
G/g (default)
F/f 12.45 Fixed point
E/e 1.245000e1 Exponential

If the method fails, iteratively increase the size of the buffer and retry until it succeeds.

Applies to

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

Source:
Utf8Formatter.TimeSpan.cs
Source:
Utf8Formatter.TimeSpan.cs
Source:
Utf8Formatter.TimeSpan.cs

Formats a TimeSpan as a UTF8 string.

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

Parameters

value
TimeSpan

The value to format.

destination
Span<Byte>

The buffer to write the UTF8-formatted value to.

bytesWritten
Int32

When the method returns, contains the length of the formatted text in bytes.

format
StandardFormat

The standard format to use.

Returns

true if the formatting operation succeeds; false if destination is too small.

Remarks

Formats supported:

Format string Result string Comments
c/t/T (default) [-][d.]hh:mm:ss[.fffffff] (constant format)
G [-]d:hh:mm:ss.fffffff (general long)
g [-][d:][h]h:mm:ss[.f[f[f[f[f[f[f]]]]]] (general short)

If the method fails, iteratively increase the size of the buffer and retry until it succeeds.

Applies to

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

Source:
Utf8Formatter.Integer.cs
Source:
Utf8Formatter.Integer.cs
Source:
Utf8Formatter.Integer.cs

Important

This API is not CLS-compliant.

Formats a UInt16 as a UTF8 string.

[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

Parameters

value
UInt16

The value to format.

destination
Span<Byte>

The buffer to write the UTF8-formatted value to.

bytesWritten
Int32

When the method returns, contains the length of the formatted text in bytes.

format
StandardFormat

The standard format to use.

Returns

true if the formatting operation succeeds; false if destination is too small.

Attributes

Remarks

Formats supported:

Format string Example result string
G/g (default)
D/d 32767
N/n 32,767
X/x 7fff

If the method fails, iteratively increase the size of the buffer and retry until it succeeds.

Applies to

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

Source:
Utf8Formatter.Integer.cs
Source:
Utf8Formatter.Integer.cs
Source:
Utf8Formatter.Integer.cs

Important

This API is not CLS-compliant.

Formats a UInt32 as a UTF8 string.

[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

Parameters

value
UInt32

The value to format.

destination
Span<Byte>

The buffer to write the UTF8-formatted value to.

bytesWritten
Int32

When the method returns, contains the length of the formatted text in bytes.

format
StandardFormat

The standard format to use.

Returns

true if the formatting operation succeeds; false if destination is too small.

Attributes

Remarks

Formats supported:

Format string Example result string
G/g (default)
D/d 32767
N/n 32,767
X/x 7fff

If the method fails, iteratively increase the size of the buffer and retry until it succeeds.

Applies to

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

Source:
Utf8Formatter.Integer.cs
Source:
Utf8Formatter.Integer.cs
Source:
Utf8Formatter.Integer.cs

Important

This API is not CLS-compliant.

Formats a UInt64 as a UTF8 string.

[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

Parameters

value
UInt64

The value to format.

destination
Span<Byte>

The buffer to write the UTF8-formatted value to.

bytesWritten
Int32

When the method returns, contains the length of the formatted text in bytes.

format
StandardFormat

The standard format to use.

Returns

true if the formatting operation succeeds; false if destination is too small.

Attributes

Remarks

Formats supported:

Format string Example result string
G/g (default)
D/d 32767
N/n 32,767
X/x 7fff

If the method fails, iteratively increase the size of the buffer and retry until it succeeds.

Applies to