Converts the string representation of a number in a specified style and culture-specific format to its Byte equivalent.
public:
static System::Byte Parse(System::String ^ s, System::Globalization::NumberStyles style, IFormatProvider ^ provider);
public:
static System::Byte Parse(System::String ^ s, System::Globalization::NumberStyles style, IFormatProvider ^ provider) = System::Numerics::INumberBase<System::Byte>::Parse;
public static byte Parse(string s, System.Globalization.NumberStyles style, IFormatProvider provider);
public static byte Parse(string s, System.Globalization.NumberStyles style, IFormatProvider? provider);
static member Parse : string * System.Globalization.NumberStyles * IFormatProvider -> byte
Public Shared Function Parse (s As String, style As NumberStyles, provider As IFormatProvider) As Byte
Parameters
A string that contains a number to convert. The string is interpreted using the style specified by style
.
A bitwise combination of enumeration values that indicates the style elements that can be present in s
. A typical value to specify is Integer.
An object that supplies culture-specific information about the format of s
. If provider
is null
, the thread current culture is used.
A byte value that is equivalent to the number contained in s
.
s
is not of the correct format.
The following code example parses string representations of Byte
values with this overload of the Byte.Parse(String, NumberStyles, IFormatProvider) method.
NumberStyles style;
CultureInfo culture;
string value;
byte number;
// Parse number with decimals.
// NumberStyles.Float includes NumberStyles.AllowDecimalPoint.
style = NumberStyles.Float;
culture = CultureInfo.CreateSpecificCulture("fr-FR");
value = "12,000";
number = Byte.Parse(value, style, culture);
Console.WriteLine("Converted '{0}' to {1}.", value, number);
culture = CultureInfo.CreateSpecificCulture("en-GB");
try
{
number = Byte.Parse(value, style, culture);
Console.WriteLine("Converted '{0}' to {1}.", value, number);
}
catch (FormatException) {
Console.WriteLine("Unable to parse '{0}'.", value); }
value = "12.000";
number = Byte.Parse(value, style, culture);
Console.WriteLine("Converted '{0}' to {1}.", value, number);
// The example displays the following output to the console:
// Converted '12,000' to 12.
// Unable to parse '12,000'.
// Converted '12.000' to 12.
// Parse number with decimals.
// NumberStyles.Float includes NumberStyles.AllowDecimalPoint.
let style = NumberStyles.Float
let culture = CultureInfo.CreateSpecificCulture "fr-FR"
let value = "12,000"
let number = Byte.Parse(value, style, culture)
printfn $"Converted '{value}' to {number}."
let culture = CultureInfo.CreateSpecificCulture "en-GB"
try
let number = Byte.Parse(value, style, culture)
printfn $"Converted '{value}' to {number}."
with :? FormatException ->
printfn $"Unable to parse '{value}'."
let value = "12.000"
let number = Byte.Parse(value, style, culture)
printfn $"Converted '{value}' to {number}."
// The example displays the following output to the console:
// Converted '12,000' to 12.
// Unable to parse '12,000'.
// Converted '12.000' to 12.
Dim style As NumberStyles
Dim culture As CultureInfo
Dim value As String
Dim number As Byte
' Parse number with decimals.
' NumberStyles.Float includes NumberStyles.AllowDecimalPoint.
style = NumberStyles.Float
culture = CultureInfo.CreateSpecificCulture("fr-FR")
value = "12,000"
number = Byte.Parse(value, style, culture)
Console.WriteLine("Converted '{0}' to {1}.", value, number)
culture = CultureInfo.CreateSpecificCulture("en-GB")
Try
number = Byte.Parse(value, style, culture)
Console.WriteLine("Converted '{0}' to {1}.", value, number)
Catch e As FormatException
Console.WriteLine("Unable to parse '{0}'.", value)
End Try
value = "12.000"
number = Byte.Parse(value, style, culture)
Console.WriteLine("Converted '{0}' to {1}.", value, number)
' The example displays the following output to the console:
' Converted '12,000' to 12.
' Unable to parse '12,000'.
' Converted '12.000' to 12.
Remarks
The style
parameter defines the style elements (such as white space or the positive sign) that are allowed in the s
parameter for the parse operation to succeed. It must be a combination of bit flags from the NumberStyles enumeration. Depending on the value of style
, the s
parameter may include the following elements:
[ws][$][sign]digits[.fractional_digits][e[sign]digits][ws]
Or, if the style
parameter includes AllowHexSpecifier:
[ws]hexdigits[ws]
Elements in square brackets ([ and ]) are optional. The following table describes each element.
Note
Any terminating NUL (U+0000) characters in s
are ignored by the parsing operation, regardless of the value of the style
argument.
A string with decimal digits only (which corresponds to the NumberStyles.None style) always parses successfully. Most of the remaining NumberStyles members control elements that may be but are not required to be present in this input string. The following table indicates how individual NumberStyles members affect the elements that may be present in s
.
If the NumberStyles.AllowHexSpecifier flag is used, s
must be a hexadecimal value without a prefix. For example, "F3" parses successfully, but "0xF3" does not. The only other flags that can be present in style
are NumberStyles.AllowLeadingWhite and NumberStyles.AllowTrailingWhite. (The NumberStyles enumeration has a composite number style, NumberStyles.HexNumber, that includes both white space flags.)
The provider
parameter is an IFormatProvider implementation, such as a NumberFormatInfo or CultureInfo object. The provider
parameter supplies culture-specific information used in parsing. If provider
is null
, the thread current culture is used.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4