Byte.Parse メソッド
定義
重要
一部の情報は、リリース前に大きく変更される可能性があるプレリリースされた製品に関するものです。 Microsoft は、ここに記載されている情報について、明示または黙示を問わず、一切保証しません。
数値の文字列形式を等価の Byte に変換します。
オーバーロード
| 名前 | 説明 |
|---|---|
| Parse(String, NumberStyles, IFormatProvider) |
指定したスタイルおよびカルチャ固有の形式の数値の文字列形式を、同等の Byte に変換します。 |
| Parse(ReadOnlySpan<Char>, NumberStyles, IFormatProvider) |
指定したスタイルおよびカルチャ固有の形式の数値のスパン表現を、同等の Byte に変換します。 |
| Parse(ReadOnlySpan<Byte>, NumberStyles, IFormatProvider) |
UTF-8 文字のスパンを値に解析します。 |
| Parse(String, IFormatProvider) |
指定したカルチャ固有の形式の数値の文字列形式を、同等の Byte に変換します。 |
| Parse(String, NumberStyles) |
指定したスタイルの数値の文字列形式を等価の Byte に変換します。 |
| Parse(ReadOnlySpan<Char>, IFormatProvider) |
文字のスパンを値に解析します。 |
| Parse(ReadOnlySpan<Byte>, IFormatProvider) |
UTF-8 文字のスパンを値に解析します。 |
| Parse(String) |
数値の文字列形式を等価の Byte に変換します。 |
Parse(String, NumberStyles, IFormatProvider)
- ソース:
- Byte.cs
- ソース:
- Byte.cs
- ソース:
- Byte.cs
- ソース:
- Byte.cs
- ソース:
- Byte.cs
指定したスタイルおよびカルチャ固有の形式の数値の文字列形式を、同等の Byte に変換します。
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
パラメーター
- s
- String
変換する数値を含む文字列。 文字列は、 styleで指定されたスタイルを使用して解釈されます。
- style
- NumberStyles
sに存在できるスタイル要素を示す列挙値のビットごとの組み合わせ。 指定する一般的な値は Integerです。
- provider
- IFormatProvider
sの形式に関するカルチャ固有の情報を提供するオブジェクト。
providerがnullされている場合は、スレッドの現在のカルチャが使用されます。
返品
sに含まれる数値に相当するバイト値。
実装
例外
s は nullです。
s が正しい形式ではありません。
例
次のコード例では、Byte.Parse(String, NumberStyles, IFormatProvider) メソッドのこのオーバーロードを使用して、Byte値の文字列表現を解析します。
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.
注釈
style パラメーターは、解析操作を成功させるために s パラメーターで許可されるスタイル要素 (空白や正符号など) を定義します。
NumberStyles列挙型のビット フラグの組み合わせである必要があります。
styleの値によっては、s パラメーターに次の要素が含まれる場合があります。
[ws][$][sign]digits[.fractional_digits][e[sign]digits][ws]
または、 style パラメーターに AllowHexSpecifierが含まれている場合は、次のようにします。
[ws]hexdigits[ws]
角かっこ ([ と ]) の要素は省略可能です。 次の表は、それぞれの要素の説明です。
| 要素 | 説明 |
|---|---|
| ws | 省略可能な空白。
NumberStyles.AllowLeadingWhite フラグが含まれている style場合はsの先頭に空白が表示され、styleにNumberStyles.AllowTrailingWhite フラグが含まれている場合はsの最後に空白が表示される場合があります。 |
| $ | カルチャ固有の通貨記号。 文字列内での位置は、NumberFormatInfo.CurrencyPositivePattern パラメーターのNumberFormatInfo メソッドによって返されるGetFormat オブジェクトのprovider プロパティによって定義されます。
sにstyleフラグが含まれている場合、通貨記号はNumberStyles.AllowCurrencySymbolに表示されます。 |
| サイン | 省略可能な正符号。 (負の符号がsに存在する場合、メソッドはOverflowExceptionをスローします)。styleにNumberStyles.AllowLeadingSign フラグが含まれている場合はsの先頭に、styleに NumberStyles.AllowTrailingSign フラグが含まれている場合はsの最後に表示されます。 |
| 桁 | 0 から 9 までの数字のシーケンス。 |
| . | カルチャ固有の小数点記号。
providerにs フラグが含まれている場合、styleで指定されたカルチャの小数点記号をNumberStyles.AllowDecimalPointに表示できます。 |
| fractional_digits | 数字 0 の 1 つ以上の出現。 小数部の数字は、sにstyle フラグが含まれている場合にのみ、NumberStyles.AllowDecimalPointに表示できます。 |
| e | e または E 文字。値が指数表記で表されることを示します。
styleにNumberStyles.AllowExponent フラグが含まれている場合、s パラメーターは指数表記で数値を表すことができます。 |
| hexdigits | 0 から f、または 0 から F までの 16 進数のシーケンス。 |
注
sで終了する NUL (U+0000) 文字は、style引数の値に関係なく、解析操作では無視されます。
10 進数のみを含む文字列 ( NumberStyles.None スタイルに対応) は、常に正常に解析されます。 残りの NumberStyles メンバーのほとんどは、この入力文字列に存在する必要がない要素を制御します。 次の表は、個々の NumberStyles メンバーが、 sに存在する可能性がある要素に与える影響を示しています。
| 非複合 NumberStyles 値 | 数字に加えて s で許可される要素 |
|---|---|
| NumberStyles.None | 10 進数のみ。 |
| NumberStyles.AllowDecimalPoint | . 要素とfractional_digits要素。 ただし、 fractional_digits は 1 つ以上の 0 桁のみで構成する必要があります。または、 OverflowException がスローされます。 |
| NumberStyles.AllowExponent |
s パラメーターでは指数表記を使用することもできます。 |
| NumberStyles.AllowLeadingWhite |
sの先頭にある ws 要素。 |
| NumberStyles.AllowTrailingWhite |
の末尾にある s 要素。 |
| NumberStyles.AllowLeadingSign | 正の符号は 数字の前に表示できます。 |
| NumberStyles.AllowTrailingSign | 正の符号は 数字の後に表示されます。 |
| NumberStyles.AllowParentheses | このフラグはサポートされていますが、 s でかっこを使用すると、 OverflowExceptionになります。 |
| NumberStyles.AllowThousands | グループ区切り記号は sに表示できますが、先頭には 1 桁以上の 0 桁のみを付けることができます。 |
| NumberStyles.AllowCurrencySymbol | $要素。 |
NumberStyles.AllowHexSpecifier フラグを使用する場合、sはプレフィックスのない 16 進数の値である必要があります。 たとえば、"F3" は正常に解析されますが、"0xF3" では解析されません。
styleに存在できるその他のフラグは、NumberStyles.AllowLeadingWhiteとNumberStyles.AllowTrailingWhiteだけです。 ( NumberStyles 列挙型には、両方の空白フラグを含む複合数値スタイル ( NumberStyles.HexNumber) があります。
provider パラメーターは、NumberFormatInfoやCultureInfo オブジェクトなどのIFormatProvider実装です。
provider パラメーターは、解析に使用されるカルチャ固有の情報を提供します。
providerがnullされている場合は、スレッドの現在のカルチャが使用されます。
こちらもご覧ください
適用対象
Parse(ReadOnlySpan<Char>, NumberStyles, IFormatProvider)
- ソース:
- Byte.cs
- ソース:
- Byte.cs
- ソース:
- Byte.cs
- ソース:
- Byte.cs
- ソース:
- Byte.cs
指定したスタイルおよびカルチャ固有の形式の数値のスパン表現を、同等の Byte に変換します。
public static byte Parse(ReadOnlySpan<char> s, System.Globalization.NumberStyles style = System.Globalization.NumberStyles.Integer, IFormatProvider? provider = default);
public static byte Parse(ReadOnlySpan<char> s, System.Globalization.NumberStyles style = System.Globalization.NumberStyles.Integer, IFormatProvider provider = default);
static member Parse : ReadOnlySpan<char> * System.Globalization.NumberStyles * IFormatProvider -> byte
Public Shared Function Parse (s As ReadOnlySpan(Of Char), Optional style As NumberStyles = System.Globalization.NumberStyles.Integer, Optional provider As IFormatProvider = Nothing) As Byte
パラメーター
- s
- ReadOnlySpan<Char>
変換する値を表す文字を含むスパン。
- style
- NumberStyles
sに存在できるスタイル要素を示す列挙値のビットごとの組み合わせ。 指定する一般的な値は Integerです。
- provider
- IFormatProvider
sの形式に関するカルチャ固有の情報を提供するオブジェクト。
providerがnullされている場合は、スレッドの現在のカルチャが使用されます。
返品
sに含まれる数値に相当するバイト値。
実装
適用対象
Parse(ReadOnlySpan<Byte>, NumberStyles, IFormatProvider)
- ソース:
- Byte.cs
- ソース:
- Byte.cs
- ソース:
- Byte.cs
- ソース:
- Byte.cs
UTF-8 文字のスパンを値に解析します。
public static byte Parse(ReadOnlySpan<byte> utf8Text, System.Globalization.NumberStyles style = System.Globalization.NumberStyles.Integer, IFormatProvider? provider = default);
static member Parse : ReadOnlySpan<byte> * System.Globalization.NumberStyles * IFormatProvider -> byte
Public Shared Function Parse (utf8Text As ReadOnlySpan(Of Byte), Optional style As NumberStyles = System.Globalization.NumberStyles.Integer, Optional provider As IFormatProvider = Nothing) As Byte
パラメーター
- utf8Text
- ReadOnlySpan<Byte>
解析する UTF-8 文字のスパン。
- style
- NumberStyles
utf8Textに存在できる数値スタイルのビットごとの組み合わせ。
- provider
- IFormatProvider
utf8Textに関するカルチャ固有の書式設定情報を提供するオブジェクト。
返品
utf8Text解析の結果。
実装
適用対象
Parse(String, IFormatProvider)
- ソース:
- Byte.cs
- ソース:
- Byte.cs
- ソース:
- Byte.cs
- ソース:
- Byte.cs
- ソース:
- Byte.cs
指定したカルチャ固有の形式の数値の文字列形式を、同等の Byte に変換します。
public:
static System::Byte Parse(System::String ^ s, IFormatProvider ^ provider);
public:
static System::Byte Parse(System::String ^ s, IFormatProvider ^ provider) = IParsable<System::Byte>::Parse;
public static byte Parse(string s, IFormatProvider provider);
public static byte Parse(string s, IFormatProvider? provider);
static member Parse : string * IFormatProvider -> byte
Public Shared Function Parse (s As String, provider As IFormatProvider) As Byte
パラメーター
- provider
- IFormatProvider
sに関するカルチャ固有の解析情報を提供するオブジェクト。
providerがnullされている場合は、スレッドの現在のカルチャが使用されます。
返品
sに含まれる数値に相当するバイト値。
実装
例外
s は nullです。
s が正しい形式ではありません。
s は、 Byte.MinValue より小さいか、 Byte.MaxValue より大きい数値を表します。
例
次の例では、Parse メソッドを使用してByte値の文字列表現を解析します。
string stringToConvert;
byte byteValue;
stringToConvert = " 214 ";
try {
byteValue = Byte.Parse(stringToConvert, CultureInfo.InvariantCulture);
Console.WriteLine("Converted '{0}' to {1}.", stringToConvert, byteValue);
}
catch (FormatException) {
Console.WriteLine("Unable to parse '{0}'.", stringToConvert); }
catch (OverflowException) {
Console.WriteLine("'{0}' is greater than {1} or less than {2}.",
stringToConvert, Byte.MaxValue, Byte.MinValue); }
stringToConvert = " + 214 ";
try {
byteValue = Byte.Parse(stringToConvert, CultureInfo.InvariantCulture);
Console.WriteLine("Converted '{0}' to {1}.", stringToConvert, byteValue);
}
catch (FormatException) {
Console.WriteLine("Unable to parse '{0}'.", stringToConvert); }
catch (OverflowException) {
Console.WriteLine("'{0}' is greater than {1} or less than {2}.",
stringToConvert, Byte.MaxValue, Byte.MinValue); }
stringToConvert = " +214 ";
try {
byteValue = Byte.Parse(stringToConvert, CultureInfo.InvariantCulture);
Console.WriteLine("Converted '{0}' to {1}.", stringToConvert, byteValue);
}
catch (FormatException) {
Console.WriteLine("Unable to parse '{0}'.", stringToConvert); }
catch (OverflowException) {
Console.WriteLine("'{0}' is greater than {1} or less than {2}.",
stringToConvert, Byte.MaxValue, Byte.MinValue); }
// The example displays the following output to the console:
// Converted ' 214 ' to 214.
// Unable to parse ' + 214 '.
// Converted ' +214 ' to 214.
let stringToConvert = " 214 "
try
let byteValue = Byte.Parse(stringToConvert, CultureInfo.InvariantCulture)
printfn $"Converted '{stringToConvert}' to {byteValue}."
with
| :? FormatException ->
printfn $"Unable to parse '{stringToConvert}'."
| :? OverflowException ->
printfn $"'{stringToConvert}' is greater than {Byte.MaxValue} or less than {Byte.MinValue}."
let stringToConvert = " + 214 "
try
let byteValue = Byte.Parse(stringToConvert, CultureInfo.InvariantCulture)
printfn $"Converted '{stringToConvert}' to {byteValue}."
with
| :? FormatException ->
printfn $"Unable to parse '{stringToConvert}'."
| :? OverflowException ->
printfn $"'{stringToConvert}' is greater than {Byte.MaxValue} or less than {Byte.MinValue}."
let stringToConvert = " +214 "
try
let byteValue = Byte.Parse(stringToConvert, CultureInfo.InvariantCulture)
printfn $"Converted '{stringToConvert}' to {byteValue}."
with
| :? FormatException ->
printfn $"Unable to parse '{stringToConvert}'."
| :? OverflowException ->
printfn $"'{stringToConvert}' is greater than {Byte.MaxValue} or less than {Byte.MinValue}."
// The example displays the following output to the console:
// Converted ' 214 ' to 214.
// Unable to parse ' + 214 '.
// Converted ' +214 ' to 214.
Dim stringToConvert As String
Dim byteValue As Byte
stringToConvert = " 214 "
Try
byteValue = Byte.Parse(stringToConvert, CultureInfo.InvariantCulture)
Console.WriteLine("Converted '{0}' to {1}.", stringToConvert, byteValue)
Catch e As FormatException
Console.WriteLine("Unable to parse '{0}'.", stringToConvert)
Catch e As OverflowException
Console.WriteLine("'{0}' is greater than {1} or less than {2}.", _
stringToConvert, Byte.MaxValue, Byte.MinValue)
End Try
stringToConvert = " + 214 "
Try
byteValue = Byte.Parse(stringToConvert, CultureInfo.InvariantCulture)
Console.WriteLine("Converted '{0}' to {1}.", stringToConvert, byteValue)
Catch e As FormatException
Console.WriteLine("Unable to parse '{0}'.", stringToConvert)
Catch e As OverflowException
Console.WriteLine("'{0}' is greater than {1} or less than {2}.", _
stringToConvert, Byte.MaxValue, Byte.MinValue)
End Try
stringToConvert = " +214 "
Try
byteValue = Byte.Parse(stringToConvert, CultureInfo.InvariantCulture)
Console.WriteLine("Converted '{0}' to {1}.", stringToConvert, byteValue)
Catch e As FormatException
Console.WriteLine("Unable to parse '{0}'.", stringToConvert)
Catch e As OverflowException
Console.WriteLine("'{0}' is greater than {1} or less than {2}.", _
stringToConvert, Byte.MaxValue, Byte.MinValue)
End Try
' The example displays the following output to the console:
' Converted ' 214 ' to 214.
' Unable to parse ' + 214 '.
' Converted ' +214 ' to 214.
注釈
s パラメーターには、次の形式が含まれています。
[ws][sign]digits[ws]
角かっこ ([ と ]) の要素は省略可能です。 次の表は、それぞれの要素の説明です。
| 要素 | 説明 |
|---|---|
| ws | 省略可能な空白。 |
| サイン | 省略可能な正符号。 |
| 桁 | 0 から 9 までの数字のシーケンス。 |
s パラメーターは、Integer スタイルを使用して解釈されます。 バイト値の 10 進数字に加えて、先頭と末尾のスペースと先頭の符号のみを使用できます。 (符号が存在する場合は、正符号であるか、メソッドが OverflowExceptionをスローする必要があります)。 sに存在できるカルチャ固有の書式設定情報と共にスタイル要素を明示的に定義するには、 Byte.Parse(String, NumberStyles, IFormatProvider) メソッドを使用します。
s パラメーターは、providerによって提供されるNumberFormatInfo オブジェクトの書式設定情報を使用して解析されます。
provider パラメーターは、NumberFormatInfoやCultureInfo オブジェクトなどのIFormatProvider実装です。
provider パラメーターは、解析に使用されるカルチャ固有の情報を提供します。
providerがnullされている場合は、スレッドの現在のカルチャが使用されます。
こちらもご覧ください
適用対象
Parse(String, NumberStyles)
- ソース:
- Byte.cs
- ソース:
- Byte.cs
- ソース:
- Byte.cs
- ソース:
- Byte.cs
- ソース:
- Byte.cs
指定したスタイルの数値の文字列形式を等価の Byte に変換します。
public:
static System::Byte Parse(System::String ^ s, System::Globalization::NumberStyles style);
public static byte Parse(string s, System.Globalization.NumberStyles style);
static member Parse : string * System.Globalization.NumberStyles -> byte
Public Shared Function Parse (s As String, style As NumberStyles) As Byte
パラメーター
- s
- String
変換する数値を含む文字列。 文字列は、 styleで指定されたスタイルを使用して解釈されます。
- style
- NumberStyles
sに存在できるスタイル要素を示す列挙値のビットごとの組み合わせ。 指定する一般的な値は Integerです。
返品
sに含まれる数値に相当するバイト値。
例外
s は nullです。
s が正しい形式ではありません。
例
次の例では、Byte.Parse(String, NumberStyles) メソッドを使用してByte値の文字列表現を解析します。 この例の現在のカルチャは en-USです。
string value;
NumberStyles style;
byte number;
// Parse value with no styles allowed.
style = NumberStyles.None;
value = " 241 ";
try
{
number = Byte.Parse(value, style);
Console.WriteLine("Converted '{0}' to {1}.", value, number);
}
catch (FormatException) {
Console.WriteLine("Unable to parse '{0}'.", value); }
// Parse value with trailing sign.
style = NumberStyles.Integer | NumberStyles.AllowTrailingSign;
value = " 163+";
number = Byte.Parse(value, style);
Console.WriteLine("Converted '{0}' to {1}.", value, number);
// Parse value with leading sign.
value = " +253 ";
number = Byte.Parse(value, style);
Console.WriteLine("Converted '{0}' to {1}.", value, number);
// This example displays the following output to the console:
// Unable to parse ' 241 '.
// Converted ' 163+' to 163.
// Converted ' +253 ' to 253.
// Parse value with no styles allowed.
let style = NumberStyles.None
let value = " 241 "
try
let number = Byte.Parse(value, style);
printfn $"Converted '{value}' to {number}."
with :? FormatException ->
printfn $"Unable to parse '{value}'."
// Parse value with trailing sign.
let style = NumberStyles.Integer ||| NumberStyles.AllowTrailingSign
let value = " 163+"
let number = Byte.Parse(value, style)
printfn $"Converted '{value}' to {number}."
// Parse value with leading sign.
let value = " +253 "
let number = Byte.Parse(value, style)
printfn $"Converted '{value}' to {number}."
// This example displays the following output to the console:
// Unable to parse ' 241 '.
// Converted ' 163+' to 163.
// Converted ' +253 ' to 253.
Dim value As String
Dim style As NumberStyles
Dim number As Byte
' Parse value with no styles allowed.
style = NumberStyles.None
value = " 241 "
Try
number = Byte.Parse(value, style)
Console.WriteLine("Converted '{0}' to {1}.", value, number)
Catch e As FormatException
Console.WriteLine("Unable to parse '{0}'.", value)
End Try
' Parse value with trailing sign.
style = NumberStyles.Integer Or NumberStyles.AllowTrailingSign
value = " 163+"
number = Byte.Parse(value, style)
Console.WriteLine("Converted '{0}' to {1}.", value, number)
' Parse value with leading sign.
value = " +253 "
number = Byte.Parse(value, style)
Console.WriteLine("Converted '{0}' to {1}.", value, number)
' This example displays the following output to the console:
' Unable to parse ' 241 '.
' Converted ' 163+' to 163.
' Converted ' +253 ' to 253.
注釈
style パラメーターは、解析操作を成功させるために s パラメーターで許可されるスタイル要素 (空白や正符号など) を定義します。
NumberStyles列挙型のビット フラグの組み合わせである必要があります。
styleの値に応じて、s パラメーターには次の要素を含めることができます。
[ws][$][sign]digits[.fractional_digits][e[sign]digits][ws]
または、AllowHexSpecifierstyle含まれている場合:
[ws]hexdigits[ws]
角かっこ ([ と ]) の要素は省略可能です。 次の表は、それぞれの要素の説明です。
| 要素 | 説明 |
|---|---|
| ws | 省略可能な空白。
styleにNumberStyles.AllowLeadingWhite フラグが含まれている場合はsの先頭に空白が表示され、スタイルに NumberStyles.AllowTrailingWhite フラグが含まれている場合は s の末尾に空白が表示されます。 |
| $ | カルチャ固有の通貨記号。 文字列内での位置は、現在のカルチャの NumberFormatInfo.CurrencyPositivePattern プロパティによって定義されます。 現在のカルチャの通貨記号は、s フラグstyle含まれている場合、NumberStyles.AllowCurrencySymbolに表示されます。 |
| サイン | 省略可能な正符号。 (負の符号がsに存在する場合、メソッドはOverflowExceptionをスローします)。styleにNumberStyles.AllowLeadingSign フラグが含まれている場合はsの先頭に、styleに NumberStyles.AllowTrailingSign フラグが含まれている場合はsの最後に表示されます。 |
| 桁 | 0 から 9 までの数字のシーケンス。 |
| . | カルチャ固有の小数点記号。 現在のカルチャの小数点記号は、s フラグstyle含まれている場合、NumberStyles.AllowDecimalPointに表示できます。 |
| fractional_digits | 数字 0 の 1 つ以上の出現。 小数部の数字は、sにstyle フラグが含まれている場合にのみ、NumberStyles.AllowDecimalPointに表示できます。 |
| e | e または E 文字。値が指数表記で表されることを示します。
s パラメーターは、style フラグが含まれている場合NumberStyles.AllowExponent指数表記で数値を表すことができます。 |
| hexdigits | 0 から f、または 0 から F までの 16 進数のシーケンス。 |
注
sで終了する NUL (U+0000) 文字は、style引数の値に関係なく、解析操作では無視されます。
10 進数のみを含む文字列 ( NumberStyles.None スタイルに対応) は、常に正常に解析されます。 残りの NumberStyles メンバーのほとんどは、この入力文字列に存在する必要がない要素を制御します。 次の表は、個々の NumberStyles メンバーが、 sに存在する可能性がある要素に与える影響を示しています。
| 非複合 NumberStyles 値 | 数字に加えて s で許可される要素 |
|---|---|
| NumberStyles.None | 10 進数のみ。 |
| NumberStyles.AllowDecimalPoint | . 要素とfractional_digits要素。 ただし、 fractional_digits は 1 つ以上の 0 桁のみで構成する必要があります。または、 OverflowException がスローされます。 |
| NumberStyles.AllowExponent |
s パラメーターでは指数表記を使用することもできます。 |
| NumberStyles.AllowLeadingWhite |
sの先頭にある ws 要素。 |
| NumberStyles.AllowTrailingWhite |
の末尾にある s 要素。 |
| NumberStyles.AllowLeadingSign | 正の符号は 数字の前に表示できます。 |
| NumberStyles.AllowTrailingSign | 正の符号は 数字の後に表示されます。 |
| NumberStyles.AllowParentheses | このフラグはサポートされていますが、 s でかっこを使用すると、 OverflowExceptionになります。 |
| NumberStyles.AllowThousands | グループ区切り記号は sに表示できますが、先頭には 1 桁以上の 0 桁のみを付けることができます。 |
| NumberStyles.AllowCurrencySymbol | $要素。 |
NumberStyles.AllowHexSpecifier フラグを使用する場合、sはプレフィックスのない 16 進数の値である必要があります。 たとえば、"F3" は正常に解析されますが、"0xF3" では解析されません。 組み合わせることができる他のフラグは、 NumberStyles.AllowLeadingWhite と NumberStyles.AllowTrailingWhiteだけです。 ( NumberStyles 列挙には、両方の空白フラグを含む複合数値スタイル ( NumberStyles.HexNumber) が含まれています)。
s パラメーターは、現在のシステム カルチャ用に初期化されたNumberFormatInfo オブジェクトの書式設定情報を使用して解析されます。 他のカルチャの書式設定情報を使用するには、 Byte.Parse(String, NumberStyles, IFormatProvider) オーバーロードを呼び出します。
こちらもご覧ください
適用対象
Parse(ReadOnlySpan<Char>, IFormatProvider)
- ソース:
- Byte.cs
- ソース:
- Byte.cs
- ソース:
- Byte.cs
- ソース:
- Byte.cs
- ソース:
- Byte.cs
文字のスパンを値に解析します。
public:
static System::Byte Parse(ReadOnlySpan<char> s, IFormatProvider ^ provider) = ISpanParsable<System::Byte>::Parse;
public static byte Parse(ReadOnlySpan<char> s, IFormatProvider? provider);
static member Parse : ReadOnlySpan<char> * IFormatProvider -> byte
Public Shared Function Parse (s As ReadOnlySpan(Of Char), provider As IFormatProvider) As Byte
パラメーター
- s
- ReadOnlySpan<Char>
解析する文字のスパン。
- provider
- IFormatProvider
sに関するカルチャ固有の書式設定情報を提供するオブジェクト。
返品
s解析の結果。
実装
適用対象
Parse(ReadOnlySpan<Byte>, IFormatProvider)
- ソース:
- Byte.cs
- ソース:
- Byte.cs
- ソース:
- Byte.cs
- ソース:
- Byte.cs
UTF-8 文字のスパンを値に解析します。
public:
static System::Byte Parse(ReadOnlySpan<System::Byte> utf8Text, IFormatProvider ^ provider) = IUtf8SpanParsable<System::Byte>::Parse;
public static byte Parse(ReadOnlySpan<byte> utf8Text, IFormatProvider? provider);
static member Parse : ReadOnlySpan<byte> * IFormatProvider -> byte
Public Shared Function Parse (utf8Text As ReadOnlySpan(Of Byte), provider As IFormatProvider) As Byte
パラメーター
- utf8Text
- ReadOnlySpan<Byte>
解析する UTF-8 文字のスパン。
- provider
- IFormatProvider
utf8Textに関するカルチャ固有の書式設定情報を提供するオブジェクト。
返品
utf8Text解析の結果。
実装
適用対象
Parse(String)
- ソース:
- Byte.cs
- ソース:
- Byte.cs
- ソース:
- Byte.cs
- ソース:
- Byte.cs
- ソース:
- Byte.cs
数値の文字列形式を等価の Byte に変換します。
public:
static System::Byte Parse(System::String ^ s);
public static byte Parse(string s);
static member Parse : string -> byte
Public Shared Function Parse (s As String) As Byte
パラメーター
返品
sに含まれる数値に相当するバイト値。
例外
s は nullです。
s が正しい形式ではありません。
s は、 Byte.MinValue より小さいか、 Byte.MaxValue より大きい数値を表します。
例
次の例では、 Byte.Parse(String) メソッドを使用して文字列値をバイト値に変換する方法を示します。 結果のバイト値がコンソールに表示されます。
string stringToConvert = " 162";
byte byteValue;
try
{
byteValue = Byte.Parse(stringToConvert);
Console.WriteLine("Converted '{0}' to {1}.", stringToConvert, byteValue);
}
catch (FormatException)
{
Console.WriteLine("Unable to parse '{0}'.", stringToConvert);
}
catch (OverflowException)
{
Console.WriteLine("'{0}' is greater than {1} or less than {2}.",
stringToConvert, Byte.MaxValue, Byte.MinValue);
}
// The example displays the following output to the console:
// Converted ' 162' to 162.
let stringToConvert = " 162"
try
let byteValue = Byte.Parse stringToConvert
printfn $"Converted '{stringToConvert}' to {byteValue}."
with
| :? FormatException ->
printfn $"Unable to parse '{stringToConvert}'."
| :? OverflowException ->
printfn $"'{stringToConvert}' is greater than {Byte.MaxValue} or less than {Byte.MinValue}."
// The example displays the following output to the console:
// Converted ' 162' to 162.
Dim stringToConvert As String = " 162"
Dim byteValue As Byte
Try
byteValue = Byte.Parse(stringToConvert)
Console.WriteLine("Converted '{0}' to {1}.", stringToConvert, byteValue)
Catch e As FormatException
Console.WriteLine("Unable to parse '{0}'.", stringToConvert)
Catch e As OverflowException
Console.WriteLine("'{0}' is greater than {1} or less than {2}.", _
stringToConvert, Byte.MaxValue, Byte.MinValue)
End Try
' The example displays the following output to the console:
' Converted ' 162' to 162.
注釈
s パラメーターには、次の形式が含まれています。
[ws][sign]digits[ws]
角かっこ ([ と ]) の要素は省略可能です。 次の表は、それぞれの要素の説明です。
| 要素 | 説明 |
|---|---|
| ws | 省略可能な空白。 |
| サイン | 省略可能な正符号または負符号。 |
| 桁 | 0 から 9 までの数字のシーケンス。 |
s パラメーターは、NumberStyles.Integer スタイルを使用して解釈されます。 バイト値の 10 進数字に加えて、先頭と末尾のスペースと先頭の符号のみを使用できます。 (符号が存在する場合は、正符号であるか、メソッドが OverflowExceptionをスローする必要があります)。 sに存在できるスタイル要素を明示的に定義するには、 Byte.Parse(String, NumberStyles) または Byte.Parse(String, NumberStyles, IFormatProvider) メソッドを使用します。
s パラメーターは、現在のシステム カルチャ用に初期化されたNumberFormatInfo オブジェクトの書式設定情報を使用して解析されます。 詳細については、CurrentInfoを参照してください。 他のカルチャの書式設定情報を使用して文字列を解析するには、 Byte.Parse(String, NumberStyles, IFormatProvider) メソッドを使用します。