Edit

Share via


Utf8Parser.TryParse Method

Definition

Overloads

TryParse(ReadOnlySpan<Byte>, Boolean, Int32, Char)

Parses a Boolean at the start of a Utf8 string.

TryParse(ReadOnlySpan<Byte>, Byte, Int32, Char)

Parses a Byte at the start of a Utf8 string.

TryParse(ReadOnlySpan<Byte>, DateTime, Int32, Char)

Parses a DateTime at the start of a Utf8 string.

TryParse(ReadOnlySpan<Byte>, DateTimeOffset, Int32, Char)

Parses a DateTimeOffset at the start of a Utf8 string.

TryParse(ReadOnlySpan<Byte>, Decimal, Int32, Char)

Parses a Decimal at the start of a Utf8 string.

TryParse(ReadOnlySpan<Byte>, Double, Int32, Char)

Parses a Double at the start of a Utf8 string.

TryParse(ReadOnlySpan<Byte>, Guid, Int32, Char)

Parses a Guid at the start of a Utf8 string.

TryParse(ReadOnlySpan<Byte>, Int16, Int32, Char)

Parses an Int16 at the start of a Utf8 string.

TryParse(ReadOnlySpan<Byte>, Int32, Int32, Char)

Parses an Int32 at the start of a Utf8 string.

TryParse(ReadOnlySpan<Byte>, Int64, Int32, Char)

Parses an Int64 at the start of a Utf8 string.

TryParse(ReadOnlySpan<Byte>, SByte, Int32, Char)

Parses an SByte at the start of a Utf8 string.

TryParse(ReadOnlySpan<Byte>, Single, Int32, Char)

Parses a Single at the start of a Utf8 string.

TryParse(ReadOnlySpan<Byte>, TimeSpan, Int32, Char)

Parses a TimeSpan at the start of a Utf8 string.

TryParse(ReadOnlySpan<Byte>, UInt16, Int32, Char)

Parses a UInt16 at the start of a Utf8 string.

TryParse(ReadOnlySpan<Byte>, UInt32, Int32, Char)

Parses a UInt32 at the start of a Utf8 string.

TryParse(ReadOnlySpan<Byte>, UInt64, Int32, Char)

Parses a UInt64 at the start of a Utf8 string.

TryParse(ReadOnlySpan<Byte>, Boolean, Int32, Char)

Source:
Utf8Parser.Boolean.cs
Source:
Utf8Parser.Boolean.cs
Source:
Utf8Parser.Boolean.cs

Parses a Boolean at the start of a Utf8 string.

public static bool TryParse (ReadOnlySpan<byte> source, out bool value, out int bytesConsumed, char standardFormat = '\0');
static member TryParse : ReadOnlySpan<byte> * bool * int * char -> bool
Public Shared Function TryParse (source As ReadOnlySpan(Of Byte), ByRef value As Boolean, ByRef bytesConsumed As Integer, Optional standardFormat As Char = '\0') As Boolean

Parameters

source
ReadOnlySpan<Byte>

The Utf8 string to parse.

value
Boolean

When the method returns, contains the value parsed from source, if the parsing operation succeeded.

bytesConsumed
Int32

If the parsing operation was successful, contains the length in bytes of the parsed substring when the method returns. If the method fails, bytesConsumed is set to 0.

standardFormat
Char

The expected format of the Utf8 string. Supported formats are 'G', 'l', and default.

Returns

true for success; false if the string was not syntactically valid or an overflow or underflow occurred.

Remarks

The parsing is case insensitive. The format parameter is validated to ensure it is supported; however, all supported formats are treated identically.

Applies to

TryParse(ReadOnlySpan<Byte>, Byte, Int32, Char)

Source:
Utf8Parser.Integer.Unsigned.cs
Source:
Utf8Parser.Integer.Unsigned.cs
Source:
Utf8Parser.Integer.Unsigned.cs

Parses a Byte at the start of a Utf8 string.

public static bool TryParse (ReadOnlySpan<byte> source, out byte value, out int bytesConsumed, char standardFormat = '\0');
static member TryParse : ReadOnlySpan<byte> * byte * int * char -> bool
Public Shared Function TryParse (source As ReadOnlySpan(Of Byte), ByRef value As Byte, ByRef bytesConsumed As Integer, Optional standardFormat As Char = '\0') As Boolean

Parameters

source
ReadOnlySpan<Byte>

The Utf8 string to parse.

value
Byte

When the method returns, contains the value parsed from source, if the parsing operation succeeded.

bytesConsumed
Int32

If the parsing operation was successful, contains the length in bytes of the parsed substring when the method returns. If the method fails, bytesConsumed is set to 0.

standardFormat
Char

The expected format of the Utf8 string.

Returns

true for success; false if the string was not syntactically valid or an overflow or underflow occurred.

Remarks

Formats supported:

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

Applies to

TryParse(ReadOnlySpan<Byte>, DateTime, Int32, Char)

Source:
Utf8Parser.Date.cs
Source:
Utf8Parser.Date.cs
Source:
Utf8Parser.Date.cs

Parses a DateTime at the start of a Utf8 string.

public static bool TryParse (ReadOnlySpan<byte> source, out DateTime value, out int bytesConsumed, char standardFormat = '\0');
static member TryParse : ReadOnlySpan<byte> * DateTime * int * char -> bool
Public Shared Function TryParse (source As ReadOnlySpan(Of Byte), ByRef value As DateTime, ByRef bytesConsumed As Integer, Optional standardFormat As Char = '\0') As Boolean

Parameters

source
ReadOnlySpan<Byte>

The Utf8 string to parse.

value
DateTime

When the method returns, contains the value parsed from source, if the parsing operation succeeded.

bytesConsumed
Int32

If the parsing operation was successful, contains the length in bytes of the parsed substring when the method returns. If the method fails, bytesConsumed is set to 0.

standardFormat
Char

The expected format of the Utf8 string.

Returns

true for success; false if the string was not syntactically valid or an overflow or underflow occurred.

Remarks

Formats supported:

Format string Example expected format 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)

Applies to

TryParse(ReadOnlySpan<Byte>, DateTimeOffset, Int32, Char)

Source:
Utf8Parser.Date.cs
Source:
Utf8Parser.Date.cs
Source:
Utf8Parser.Date.cs

Parses a DateTimeOffset at the start of a Utf8 string.

public static bool TryParse (ReadOnlySpan<byte> source, out DateTimeOffset value, out int bytesConsumed, char standardFormat = '\0');
static member TryParse : ReadOnlySpan<byte> * DateTimeOffset * int * char -> bool
Public Shared Function TryParse (source As ReadOnlySpan(Of Byte), ByRef value As DateTimeOffset, ByRef bytesConsumed As Integer, Optional standardFormat As Char = '\0') As Boolean

Parameters

source
ReadOnlySpan<Byte>

The Utf8 string to parse.

value
DateTimeOffset

When the method returns, contains the value parsed from source, if the parsing operation succeeded.

bytesConsumed
Int32

If the parsing operation was successful, contains the length in bytes of the parsed substring when the method returns. If the method fails, bytesConsumed is set to 0.

standardFormat
Char

The expected format of the Utf8 string.

Returns

true for success; false if the string was not syntactically valid or an overflow or underflow occurred.

Remarks

Formats supported:

Format string Example expected format 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)

Applies to

TryParse(ReadOnlySpan<Byte>, Decimal, Int32, Char)

Source:
Utf8Parser.Decimal.cs
Source:
Utf8Parser.Decimal.cs
Source:
Utf8Parser.Decimal.cs

Parses a Decimal at the start of a Utf8 string.

public static bool TryParse (ReadOnlySpan<byte> source, out decimal value, out int bytesConsumed, char standardFormat = '\0');
static member TryParse : ReadOnlySpan<byte> * decimal * int * char -> bool
Public Shared Function TryParse (source As ReadOnlySpan(Of Byte), ByRef value As Decimal, ByRef bytesConsumed As Integer, Optional standardFormat As Char = '\0') As Boolean

Parameters

source
ReadOnlySpan<Byte>

The Utf8 string to parse.

value
Decimal

When the method returns, contains the value parsed from source, if the parsing operation succeeded.

bytesConsumed
Int32

If the parsing operation was successful, contains the length in bytes of the parsed substring when the method returns. If the method fails, bytesConsumed is set to 0.

standardFormat
Char

The expected format of the Utf8 string.

Returns

true for success; false if the string was not syntactically valid or an overflow or underflow occurred.

Remarks

Formats supported:

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

Applies to

TryParse(ReadOnlySpan<Byte>, Double, Int32, Char)

Source:
Utf8Parser.Float.cs
Source:
Utf8Parser.Float.cs
Source:
Utf8Parser.Float.cs

Parses a Double at the start of a Utf8 string.

public static bool TryParse (ReadOnlySpan<byte> source, out double value, out int bytesConsumed, char standardFormat = '\0');
static member TryParse : ReadOnlySpan<byte> * double * int * char -> bool
Public Shared Function TryParse (source As ReadOnlySpan(Of Byte), ByRef value As Double, ByRef bytesConsumed As Integer, Optional standardFormat As Char = '\0') As Boolean

Parameters

source
ReadOnlySpan<Byte>

The Utf8 string to parse.

value
Double

When the method returns, contains the value parsed from source, if the parsing operation succeeded.

bytesConsumed
Int32

If the parsing operation was successful, contains the length in bytes of the parsed substring when the method returns. If the method fails, bytesConsumed is set to 0.

standardFormat
Char

The expected format of the Utf8 string.

Returns

true for success; false if the string was not syntactically valid or an overflow or underflow occurred.

Remarks

Formats supported:

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

Applies to

TryParse(ReadOnlySpan<Byte>, Guid, Int32, Char)

Source:
Utf8Parser.Guid.cs
Source:
Utf8Parser.Guid.cs
Source:
Utf8Parser.Guid.cs

Parses a Guid at the start of a Utf8 string.

public static bool TryParse (ReadOnlySpan<byte> source, out Guid value, out int bytesConsumed, char standardFormat = '\0');
static member TryParse : ReadOnlySpan<byte> * Guid * int * char -> bool
Public Shared Function TryParse (source As ReadOnlySpan(Of Byte), ByRef value As Guid, ByRef bytesConsumed As Integer, Optional standardFormat As Char = '\0') As Boolean

Parameters

source
ReadOnlySpan<Byte>

The Utf8 string to parse.

value
Guid

When the method returns, contains the value parsed from source, if the parsing operation succeeded.

bytesConsumed
Int32

If the parsing operation was successful, contains the length in bytes of the parsed substring when the method returns. If the method fails, bytesConsumed is set to 0.

standardFormat
Char

The expected format of the Utf8 string.

Returns

true for success; false if the string was not syntactically valid or an overflow or underflow occurred.

Remarks

Formats supported:

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

Applies to

TryParse(ReadOnlySpan<Byte>, Int16, Int32, Char)

Source:
Utf8Parser.Integer.Signed.cs
Source:
Utf8Parser.Integer.Signed.cs
Source:
Utf8Parser.Integer.Signed.cs

Parses an Int16 at the start of a Utf8 string.

public static bool TryParse (ReadOnlySpan<byte> source, out short value, out int bytesConsumed, char standardFormat = '\0');
static member TryParse : ReadOnlySpan<byte> * int16 * int * char -> bool
Public Shared Function TryParse (source As ReadOnlySpan(Of Byte), ByRef value As Short, ByRef bytesConsumed As Integer, Optional standardFormat As Char = '\0') As Boolean

Parameters

source
ReadOnlySpan<Byte>

The Utf8 string to parse.

value
Int16

When the method returns, contains the value parsed from source, if the parsing operation succeeded.

bytesConsumed
Int32

If the parsing operation was successful, contains the length in bytes of the parsed substring when the method returns. If the method fails, bytesConsumed is set to 0.

standardFormat
Char

The expected format of the Utf8 string.

Returns

true for success; false if the string was not syntactically valid or an overflow or underflow occurred.

Remarks

Formats supported:

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

Applies to

TryParse(ReadOnlySpan<Byte>, Int32, Int32, Char)

Source:
Utf8Parser.Integer.Signed.cs
Source:
Utf8Parser.Integer.Signed.cs
Source:
Utf8Parser.Integer.Signed.cs

Parses an Int32 at the start of a Utf8 string.

public static bool TryParse (ReadOnlySpan<byte> source, out int value, out int bytesConsumed, char standardFormat = '\0');
static member TryParse : ReadOnlySpan<byte> * int * int * char -> bool
Public Shared Function TryParse (source As ReadOnlySpan(Of Byte), ByRef value As Integer, ByRef bytesConsumed As Integer, Optional standardFormat As Char = '\0') As Boolean

Parameters

source
ReadOnlySpan<Byte>

The Utf8 string to parse.

value
Int32

When the method returns, contains the value parsed from source, if the parsing operation succeeded.

bytesConsumed
Int32

If the parsing operation was successful, contains the length in bytes of the parsed substring when the method returns. If the method fails, bytesConsumed is set to 0.

standardFormat
Char

The expected format of the Utf8 string.

Returns

true for success; false if the string was not syntactically valid or an overflow or underflow occurred.

Remarks

Formats supported:

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

Applies to

TryParse(ReadOnlySpan<Byte>, Int64, Int32, Char)

Source:
Utf8Parser.Integer.Signed.cs
Source:
Utf8Parser.Integer.Signed.cs
Source:
Utf8Parser.Integer.Signed.cs

Parses an Int64 at the start of a Utf8 string.

public static bool TryParse (ReadOnlySpan<byte> source, out long value, out int bytesConsumed, char standardFormat = '\0');
static member TryParse : ReadOnlySpan<byte> * int64 * int * char -> bool
Public Shared Function TryParse (source As ReadOnlySpan(Of Byte), ByRef value As Long, ByRef bytesConsumed As Integer, Optional standardFormat As Char = '\0') As Boolean

Parameters

source
ReadOnlySpan<Byte>

The Utf8 string to parse.

value
Int64

When the method returns, contains the value parsed from source, if the parsing operation succeeded.

bytesConsumed
Int32

If the parsing operation was successful, contains the length in bytes of the parsed substring when the method returns. If the method fails, bytesConsumed is set to 0.

standardFormat
Char

The expected format of the Utf8 string.

Returns

true for success; false if the string was not syntactically valid or an overflow or underflow occurred.

Remarks

Formats supported:

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

Applies to

TryParse(ReadOnlySpan<Byte>, SByte, Int32, Char)

Source:
Utf8Parser.Integer.Signed.cs
Source:
Utf8Parser.Integer.Signed.cs
Source:
Utf8Parser.Integer.Signed.cs

Important

This API is not CLS-compliant.

Parses an SByte at the start of a Utf8 string.

[System.CLSCompliant(false)]
public static bool TryParse (ReadOnlySpan<byte> source, out sbyte value, out int bytesConsumed, char standardFormat = '\0');
[<System.CLSCompliant(false)>]
static member TryParse : ReadOnlySpan<byte> * sbyte * int * char -> bool
Public Shared Function TryParse (source As ReadOnlySpan(Of Byte), ByRef value As SByte, ByRef bytesConsumed As Integer, Optional standardFormat As Char = '\0') As Boolean

Parameters

source
ReadOnlySpan<Byte>

The Utf8 string to parse.

value
SByte

When the method returns, contains the value parsed from source, if the parsing operation succeeded.

bytesConsumed
Int32

If the parsing operation was successful, contains the length in bytes of the parsed substring when the method returns. If the method fails, bytesConsumed is set to 0.

standardFormat
Char

The expected format of the Utf8 string.

Returns

true for success; false if the string was not syntactically valid or an overflow or underflow occurred.

Attributes

Remarks

Formats supported:

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

Applies to

TryParse(ReadOnlySpan<Byte>, Single, Int32, Char)

Source:
Utf8Parser.Float.cs
Source:
Utf8Parser.Float.cs
Source:
Utf8Parser.Float.cs

Parses a Single at the start of a Utf8 string.

public static bool TryParse (ReadOnlySpan<byte> source, out float value, out int bytesConsumed, char standardFormat = '\0');
static member TryParse : ReadOnlySpan<byte> * single * int * char -> bool
Public Shared Function TryParse (source As ReadOnlySpan(Of Byte), ByRef value As Single, ByRef bytesConsumed As Integer, Optional standardFormat As Char = '\0') As Boolean

Parameters

source
ReadOnlySpan<Byte>

The Utf8 string to parse.

value
Single

When the method returns, contains the value parsed from source, if the parsing operation succeeded.

bytesConsumed
Int32

If the parsing operation was successful, contains the length in bytes of the parsed substring when the method returns. If the method fails, bytesConsumed is set to 0.

standardFormat
Char

The expected format of the Utf8 string.

Returns

true for success; false if the string was not syntactically valid or an overflow or underflow occurred.

Remarks

Formats supported:

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

Applies to

TryParse(ReadOnlySpan<Byte>, TimeSpan, Int32, Char)

Source:
Utf8Parser.TimeSpan.cs
Source:
Utf8Parser.TimeSpan.cs
Source:
Utf8Parser.TimeSpan.cs

Parses a TimeSpan at the start of a Utf8 string.

public static bool TryParse (ReadOnlySpan<byte> source, out TimeSpan value, out int bytesConsumed, char standardFormat = '\0');
static member TryParse : ReadOnlySpan<byte> * TimeSpan * int * char -> bool
Public Shared Function TryParse (source As ReadOnlySpan(Of Byte), ByRef value As TimeSpan, ByRef bytesConsumed As Integer, Optional standardFormat As Char = '\0') As Boolean

Parameters

source
ReadOnlySpan<Byte>

The Utf8 string to parse.

value
TimeSpan

When the method returns, contains the value parsed from source, if the parsing operation succeeded.

bytesConsumed
Int32

If the parsing operation was successful, contains the length in bytes of the parsed substring when the method returns. If the method fails, bytesConsumed is set to 0.

standardFormat
Char

The expected format of the Utf8 string.

Returns

true for success; false if the string was not syntactically valid or an overflow or underflow occurred.

Remarks

Formats supported:

Format string Expected format 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)

Applies to

TryParse(ReadOnlySpan<Byte>, UInt16, Int32, Char)

Source:
Utf8Parser.Integer.Unsigned.cs
Source:
Utf8Parser.Integer.Unsigned.cs
Source:
Utf8Parser.Integer.Unsigned.cs

Important

This API is not CLS-compliant.

Parses a UInt16 at the start of a Utf8 string.

[System.CLSCompliant(false)]
public static bool TryParse (ReadOnlySpan<byte> source, out ushort value, out int bytesConsumed, char standardFormat = '\0');
[<System.CLSCompliant(false)>]
static member TryParse : ReadOnlySpan<byte> * uint16 * int * char -> bool
Public Shared Function TryParse (source As ReadOnlySpan(Of Byte), ByRef value As UShort, ByRef bytesConsumed As Integer, Optional standardFormat As Char = '\0') As Boolean

Parameters

source
ReadOnlySpan<Byte>

The Utf8 string to parse.

value
UInt16

When the method returns, contains the value parsed from source, if the parsing operation succeeded.

bytesConsumed
Int32

If the parsing operation was successful, contains the length in bytes of the parsed substring when the method returns. If the method fails, bytesConsumed is set to 0.

standardFormat
Char

The expected format of the Utf8 string.

Returns

true for success; false if the string was not syntactically valid or an overflow or underflow occurred.

Attributes

Remarks

Formats supported:

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

Applies to

TryParse(ReadOnlySpan<Byte>, UInt32, Int32, Char)

Source:
Utf8Parser.Integer.Unsigned.cs
Source:
Utf8Parser.Integer.Unsigned.cs
Source:
Utf8Parser.Integer.Unsigned.cs

Important

This API is not CLS-compliant.

Parses a UInt32 at the start of a Utf8 string.

[System.CLSCompliant(false)]
public static bool TryParse (ReadOnlySpan<byte> source, out uint value, out int bytesConsumed, char standardFormat = '\0');
[<System.CLSCompliant(false)>]
static member TryParse : ReadOnlySpan<byte> * uint32 * int * char -> bool
Public Shared Function TryParse (source As ReadOnlySpan(Of Byte), ByRef value As UInteger, ByRef bytesConsumed As Integer, Optional standardFormat As Char = '\0') As Boolean

Parameters

source
ReadOnlySpan<Byte>

The Utf8 string to parse.

value
UInt32

When the method returns, contains the value parsed from source, if the parsing operation succeeded.

bytesConsumed
Int32

If the parsing operation was successful, contains the length in bytes of the parsed substring when the method returns. If the method fails, bytesConsumed is set to 0.

standardFormat
Char

The expected format of the Utf8 string.

Returns

true for success; false if the string was not syntactically valid or an overflow or underflow occurred.

Attributes

Remarks

Formats supported:

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

Applies to

TryParse(ReadOnlySpan<Byte>, UInt64, Int32, Char)

Source:
Utf8Parser.Integer.Unsigned.cs
Source:
Utf8Parser.Integer.Unsigned.cs
Source:
Utf8Parser.Integer.Unsigned.cs

Important

This API is not CLS-compliant.

Parses a UInt64 at the start of a Utf8 string.

[System.CLSCompliant(false)]
public static bool TryParse (ReadOnlySpan<byte> source, out ulong value, out int bytesConsumed, char standardFormat = '\0');
[<System.CLSCompliant(false)>]
static member TryParse : ReadOnlySpan<byte> * uint64 * int * char -> bool
Public Shared Function TryParse (source As ReadOnlySpan(Of Byte), ByRef value As ULong, ByRef bytesConsumed As Integer, Optional standardFormat As Char = '\0') As Boolean

Parameters

source
ReadOnlySpan<Byte>

The Utf8 string to parse.

value
UInt64

When the method returns, contains the value parsed from source, if the parsing operation succeeded.

bytesConsumed
Int32

If the parsing operation was successful, contains the length in bytes of the parsed substring when the method returns. If the method fails, bytesConsumed is set to 0.

standardFormat
Char

The expected format of the Utf8 string.

Returns

true for success; false if the string was not syntactically valid or an overflow or underflow occurred.

Attributes

Remarks

Formats supported:

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

Applies to