Byte.Parse 메서드
정의
중요
일부 정보는 릴리스되기 전에 상당 부분 수정될 수 있는 시험판 제품과 관련이 있습니다. Microsoft는 여기에 제공된 정보에 대해 어떠한 명시적이거나 묵시적인 보증도 하지 않습니다.
숫자의 문자열 표현을 해당하는 값으로 Byte 변환합니다.
오버로드
| Name | Description |
|---|---|
| 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)
- Source:
- Byte.cs
- Source:
- Byte.cs
- Source:
- Byte.cs
- Source:
- Byte.cs
- Source:
- 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.
null이 경우 provider 스레드 현재 문화권이 사용됩니다.
반환
에 포함된 s숫자와 동일한 바이트 값입니다.
구현
예외
s은 null입니다.
s 가 올바른 형식이 아닌 경우
예제
다음 코드 예제에서는 메서드의 이 오버로드를 사용하여 값의 Byte 문자열 표현을 구문 분석합니다 Byte.Parse(String, NumberStyles, IFormatProvider) .
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 | 선택적 공백 플래그가 포함된 경우의 s 시작 부분이나 플래그가 포함된 NumberStyles.AllowLeadingWhite 경우 style 의 s 끝에 공백이 NumberStyles.AllowTrailingWhite 나타날 수 style 있습니다. |
| $ | 문화권별 통화 기호입니다. 문자열의 위치는 매개 변수 메서드에서 반환된 NumberFormatInfo.CurrencyPositivePattern 개체의 속성에 NumberFormatInfoGetFormat 의해 provider 정의됩니다. 플래그를 포함하는 경우 s 통화 기호가 style 나타날 NumberStyles.AllowCurrencySymbol 수 있습니다. |
| 서명 | 선택적 양수 기호입니다. (메서드는 음수 OverflowException 기호가 s있는 경우를 throw합니다.) 플래그가 포함된 경우의 s 시작 부분 또는 플래그가 포함된 NumberStyles.AllowLeadingSignNumberStyles.AllowTrailingSign 경우의 s 끝에 표시할 style 수 style 있습니다. |
| 자리 | 0에서 9까지의 숫자 시퀀스입니다. |
| . | 문화권별 소수점 기호입니다. 플래그를 포함하는 경우 provider 지정된 s 문화권의 소수점 기호가 styleNumberStyles.AllowDecimalPoint 나타날 수 있습니다. |
| fractional_digits | 숫자 0이 하나 이상 발생합니다. 소수 자릿수는 플래그를 포함하는 경우에만 s 표시 style 할 NumberStyles.AllowDecimalPoint 수 있습니다. |
| e | 값이 지수 표기법으로 표시됨을 나타내는 e 또는 E 문자입니다. 플래그를 포함하는 경우 style s 매개 변수는 지수 표기법의 NumberStyles.AllowExponent 숫자를 나타낼 수 있습니다. |
| hexdigits | 0부터 f까지의 16진수 숫자 또는 0부터 F까지의 시퀀스입니다. |
메모
인수 값 s 에 관계없이 구문 분석 작업에서 style 종료되는 NUL(U+0000) 문자는 무시됩니다.
10진수만 있는 문자열(스타일에 NumberStyles.None 해당)은 항상 성공적으로 구문 분석됩니다. 나머지 NumberStyles 멤버의 대부분은 이 입력 문자열에 있을 수 있지만 필요하지 않은 요소를 제어합니다. 다음 표에서는 개별 NumberStyles 멤버가 에 있을 s수 있는 요소에 미치는 영향을 나타냅니다.
| 복합이 아닌 NumberStyles 값 | 숫자 외에도 s에 허용되는 요소 |
|---|---|
| NumberStyles.None | 10진수에만 해당합니다. |
| NumberStyles.AllowDecimalPoint | 요소 및 fractional_digits. 그러나 fractional_digits 하나 이상의 0자리 숫자 OverflowException 로만 구성되거나 throw됩니다. |
| NumberStyles.AllowExponent | 매개 변수는 s 지수 표기법을 사용할 수도 있습니다. |
| NumberStyles.AllowLeadingWhite | 의 시작 부분에 있는 ws 요소입니다 s. |
| NumberStyles.AllowTrailingWhite | 의 끝에 있는 ws 요소입니다 s. |
| NumberStyles.AllowLeadingSign | 양수 기호는 숫자 앞에 나타날 수 있습니다. |
| NumberStyles.AllowTrailingSign | 숫자 뒤의 양수 기호 가 나타날 수 있습니다. |
| NumberStyles.AllowParentheses | 이 플래그는 지원되지만 괄호 sOverflowException를 사용하면 . |
| NumberStyles.AllowThousands | 그룹 구분 기호가 s나타날 수 있지만 앞에는 하나 이상의 0자리 숫자만 표시될 수 있습니다. |
| NumberStyles.AllowCurrencySymbol | 요소입니다 $ . |
플래그를 NumberStyles.AllowHexSpecifier 사용하는 s 경우 접두사 없이 16진수 값이어야 합니다. 예를 들어 "F3"은 성공적으로 구문 분석되지만 "0xF3"는 구문 분석되지 않습니다. 존재 style 할 수 있는 유일한 다른 플래그는 다음과 같습니다 NumberStyles.AllowLeadingWhiteNumberStyles.AllowTrailingWhite. 열거형에는 NumberStyles 공백 플래그를 모두 포함하는 복합 숫자 스타일 NumberStyles.HexNumber이 있습니다.
provider 매개 변수는 개체와 CultureInfo 같은 구현입니다 IFormatProviderNumberFormatInfo. 매개 변수는 provider 구문 분석에서 사용되는 문화권별 정보를 제공합니다.
null이 경우 provider 스레드 현재 문화권이 사용됩니다.
추가 정보
적용 대상
Parse(ReadOnlySpan<Char>, NumberStyles, IFormatProvider)
- Source:
- Byte.cs
- Source:
- Byte.cs
- Source:
- Byte.cs
- Source:
- Byte.cs
- Source:
- 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.
null이 경우 provider 스레드 현재 문화권이 사용됩니다.
반환
에 포함된 s숫자와 동일한 바이트 값입니다.
구현
적용 대상
Parse(ReadOnlySpan<Byte>, NumberStyles, IFormatProvider)
- Source:
- Byte.cs
- Source:
- Byte.cs
- Source:
- Byte.cs
- Source:
- 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)
- Source:
- Byte.cs
- Source:
- Byte.cs
- Source:
- Byte.cs
- Source:
- Byte.cs
- Source:
- 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.
null이 경우 provider 스레드 현재 문화권이 사용됩니다.
반환
에 포함된 s숫자와 동일한 바이트 값입니다.
구현
예외
s은 null입니다.
s 가 올바른 형식이 아닌 경우
s 는 Byte.MinValue 보다 작거나 Byte.MaxValue보다 큰 숫자를 나타냅니다.
예제
다음 예제에서는 메서드를 사용하여 값의 Byte 문자열 표현을 Parse 구문 분석합니다.
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 . 바이트 값의 소수 자릿수 외에도 선행 기호와 함께 선행 및 후행 공백만 허용됩니다. (기호가 있는 경우 양수 기호여야 하거나 메서드 OverflowException가 .) 스타일 요소를 문화권별 서식 정보와 함께 명시적으로 정의하려면 메서드 s를 Byte.Parse(String, NumberStyles, IFormatProvider) 사용합니다.
s 매개 변수는 제공된 개체의 서식 정보를 NumberFormatInfo 사용하여 구문 분석됩니다provider.
provider 매개 변수는 개체와 CultureInfo 같은 구현입니다 NumberFormatInfoIFormatProvider. 매개 변수는 provider 구문 분석에서 사용되는 문화권별 정보를 제공합니다.
null이 경우 provider 스레드 현재 문화권이 사용됩니다.
추가 정보
적용 대상
Parse(String, NumberStyles)
- Source:
- Byte.cs
- Source:
- Byte.cs
- Source:
- Byte.cs
- Source:
- Byte.cs
- Source:
- 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 문자열 표현을 Byte.Parse(String, NumberStyles) 구문 분석합니다. 예제의 현재 문화권은 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]
또는 다음이 포함된 AllowHexSpecifier경우style:
[ws]hexdigits[ws]
대괄호([ 및 ])의 요소는 선택 사항입니다. 다음 표에서는 각 요소에 대해 설명합니다.
| 요소 | 설명 |
|---|---|
| ws | 선택적 공백 플래그가 포함된 경우 style 의 s 시작 부분에 공백이 NumberStyles.AllowLeadingWhite 표시되거나 스타일에 플래그가 포함된 경우 끝에 공백이 NumberStyles.AllowTrailingWhite 나타날 수 있습니다. |
| $ | 문화권별 통화 기호입니다. 문자열의 위치는 현재 문화권의 NumberFormatInfo.CurrencyPositivePattern 속성에 의해 정의됩니다. 플래그가 포함된 경우 s 현재 문화권의 통화 기호가 styleNumberStyles.AllowCurrencySymbol 나타날 수 있습니다. |
| 서명 | 선택적 양수 기호입니다. (메서드는 음수 OverflowException 기호가 s있는 경우를 throw합니다.) 플래그가 포함된 경우의 s 시작 부분 또는 플래그가 포함된 NumberStyles.AllowLeadingSignNumberStyles.AllowTrailingSign 경우의 s 끝에 표시할 style 수 style 있습니다. |
| 자리 | 0에서 9까지의 숫자 시퀀스입니다. |
| . | 문화권별 소수점 기호입니다. 플래그가 포함된 경우 s 현재 문화권의 소수점 기호가 styleNumberStyles.AllowDecimalPoint 나타날 수 있습니다. |
| fractional_digits | 숫자 0이 하나 이상 발생합니다. 소수 자릿수는 플래그를 포함하는 경우에만 s 표시 style 할 NumberStyles.AllowDecimalPoint 수 있습니다. |
| e | 값이 지수 표기법으로 표시됨을 나타내는 e 또는 E 문자입니다. 플래그를 포함하는 경우 s 매개 변수는 style 지수 표기법으로 NumberStyles.AllowExponent 숫자를 나타낼 수 있습니다. |
| hexdigits | 0부터 f까지의 16진수 숫자 또는 0부터 F까지의 시퀀스입니다. |
메모
인수 값 s 에 관계없이 구문 분석 작업에서 style 종료되는 NUL(U+0000) 문자는 무시됩니다.
10진수만 있는 문자열(스타일에 NumberStyles.None 해당)은 항상 성공적으로 구문 분석됩니다. 나머지 NumberStyles 멤버의 대부분은 이 입력 문자열에 있을 수 있지만 필요하지 않은 요소를 제어합니다. 다음 표에서는 개별 NumberStyles 멤버가 에 있을 s수 있는 요소에 미치는 영향을 나타냅니다.
| 복합이 아닌 NumberStyles 값 | 숫자 외에도 s에 허용되는 요소 |
|---|---|
| NumberStyles.None | 10진수에만 해당합니다. |
| NumberStyles.AllowDecimalPoint | 요소 및 fractional_digits. 그러나 fractional_digits 하나 이상의 0자리 숫자 OverflowException 로만 구성되거나 throw됩니다. |
| NumberStyles.AllowExponent | 매개 변수는 s 지수 표기법을 사용할 수도 있습니다. |
| NumberStyles.AllowLeadingWhite | 의 시작 부분에 있는 ws 요소입니다 s. |
| NumberStyles.AllowTrailingWhite | 의 끝에 있는 ws 요소입니다 s. |
| NumberStyles.AllowLeadingSign | 양수 기호는 숫자 앞에 나타날 수 있습니다. |
| NumberStyles.AllowTrailingSign | 숫자 뒤의 양수 기호 가 나타날 수 있습니다. |
| NumberStyles.AllowParentheses | 이 플래그는 지원되지만 괄호 sOverflowException를 사용하면 . |
| NumberStyles.AllowThousands | 그룹 구분 기호가 s나타날 수 있지만 앞에는 하나 이상의 0자리 숫자만 표시될 수 있습니다. |
| NumberStyles.AllowCurrencySymbol | 요소입니다 $ . |
플래그를 NumberStyles.AllowHexSpecifier 사용하는 s 경우 접두사 없이 16진수 값이어야 합니다. 예를 들어 "F3"은 성공적으로 구문 분석되지만 "0xF3"는 구문 분석되지 않습니다. 결합할 수 있는 유일한 다른 플래그는 다음과 NumberStyles.AllowTrailingWhite같습니다NumberStyles.AllowLeadingWhite. (열거형에는 NumberStyles 공백 플래그를 모두 포함하는 복합 숫자 스타일 NumberStyles.HexNumber이 포함됩니다.)
매개 s 변수는 현재 시스템 문화권에 대해 초기화된 개체의 NumberFormatInfo 서식 정보를 사용하여 구문 분석됩니다. 다른 문화권의 서식 정보를 사용하려면 오버로드를 호출합니다 Byte.Parse(String, NumberStyles, IFormatProvider) .
추가 정보
적용 대상
Parse(ReadOnlySpan<Char>, IFormatProvider)
- Source:
- Byte.cs
- Source:
- Byte.cs
- Source:
- Byte.cs
- Source:
- Byte.cs
- Source:
- 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)
- Source:
- Byte.cs
- Source:
- Byte.cs
- Source:
- Byte.cs
- Source:
- 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)
- Source:
- Byte.cs
- Source:
- Byte.cs
- Source:
- Byte.cs
- Source:
- Byte.cs
- Source:
- 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 . 바이트 값의 소수 자릿수 외에도 선행 기호와 함께 선행 및 후행 공백만 허용됩니다. (기호가 있는 경우 양수 기호여야 하거나 메서드 OverflowException가 .) 존재 s할 수 있는 스타일 요소를 명시적으로 정의하려면 메서드 또는 메서드를 Byte.Parse(String, NumberStyles)Byte.Parse(String, NumberStyles, IFormatProvider) 사용합니다.
매개 s 변수는 현재 시스템 문화권에 대해 초기화된 개체의 NumberFormatInfo 서식 정보를 사용하여 구문 분석됩니다. 자세한 내용은 CurrentInfo를 참조하세요. 다른 문화권의 서식 정보를 사용하여 문자열을 구문 분석하려면 이 메서드를 Byte.Parse(String, NumberStyles, IFormatProvider) 사용합니다.