Byte.Parse 메서드

정의

숫자의 문자열 표현을 해당하는 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)

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의 형식에 대한 문화권별 정보를 제공하는 개체입니다. providernull이면 현재 스레드 문화권이 사용됩니다.

반환

s에 포함된 수와 같은 바이트 값입니다.

구현

예외

s이(가) null인 경우

s의 형식이 올바르지 않습니다.

sByte.MinValue 보다 작거나 Byte.MaxValue보다 큰 숫자를 나타냅니다.

또는

s에 0이 아닌 소수 자릿수가 포함되어 있습니다.

styleNumberStyles 값이 아닙니다.

또는

styleAllowHexSpecifierHexNumber 값의 조합이 아닙니다.

예제

다음 코드 예제에서는 메서드의 이 오버로드를 사용하여 값의 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.
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]

또는 매개 변수에 가 포함된 경우 입니다 styleAllowHexSpecifier.

[ws]hexdigits[ws]

대괄호 ([ 및 ]) 안의 요소는 선택적 요소입니다. 다음 표에서는 각 요소에 대해 설명합니다.

요소 설명
ws 선택적 공백입니다. 플래그가 포함된 경우 의 s 시작 부분에 공백이 표시되거나, 플래그가 NumberStyles.AllowLeadingWhite 포함된 경우 styles 끝에 공백이 NumberStyles.AllowTrailingWhite 표시될 수 style 있습니다.
$ 문화권별 통화 기호입니다. 문자열의 위치는 매개 변수의 메서드 provider 에서 반환된 NumberFormatInfo 개체의 속성에 GetFormat 의해 NumberFormatInfo.CurrencyPositivePattern 정의됩니다. 플래그가 포함된 경우 style 통화 기호가 NumberStyles.AllowCurrencySymbols 나타날 수 있습니다.
sign 선택적 양수 기호입니다. (에 음수 기호가 OverflowException 있으면 메서드가 을 sthrow합니다.) 플래그를 포함하는 경우 의 s 시작 부분에 기호가 표시되거나 플래그가 NumberStyles.AllowLeadingSign 포함된 경우 styles 끝에 표시할 NumberStyles.AllowTrailingSignstyle 있습니다.
숫자 0에서 9까지의 숫자 시퀀스입니다.
. 문화권별 소수점 기호입니다. 에 지정된 provider 문화권의 소수점 기호가 플래그를 포함하는 NumberStyles.AllowDecimalPoint 경우 styles 나타날 수 있습니다.
fractional_digits 숫자 0이 하나 이상 발생합니다. 소수 자릿수는 플래그가 포함된 경우에만 styles 표시할 NumberStyles.AllowDecimalPoint 수 있습니다.
e 값이 지수 표기법으로 표시됨을 나타내는 e 또는 E 문자입니다. 플래그가 포함된 경우 style s 매개 변수는 지수 표기법으로 NumberStyles.AllowExponent 숫자를 나타낼 수 있습니다.
hexdigits 0에서 f까지 또는 0부터 F까지의 16진수 숫자 시퀀스입니다.

참고

의 종결 NUL(U+0000) 문자는 인수 값 style 에 관계없이 구문 분석 작업에서 s 무시됩니다.

10진수만 있는 문자열(스타일에 NumberStyles.None 해당)은 항상 성공적으로 구문 분석됩니다. 나머지 NumberStyles 멤버의 대부분은 이 입력 문자열에 있을 수 있지만 필요하지 않은 요소를 제어합니다. 다음 표에서는 개별 NumberStyles 멤버가 에 s있을 수 있는 요소에 미치는 영향을 나타냅니다.

복합이 아닌 NumberStyles 값 숫자 외에 에서 허용되는 요소
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 이 플래그는 지원되지만 에서 괄호를 s 사용하면 가 생성 OverflowException됩니다.
NumberStyles.AllowThousands 그룹 구분 기호는 에 s표시될 수 있지만 앞에 0자리 이상만 표시할 수 있습니다.
NumberStyles.AllowCurrencySymbol $ 요소입니다.

플래그를 NumberStyles.AllowHexSpecifier 사용하는 s 경우 는 접두사 없이 16진수 값이어야 합니다. 예를 들어 "F3"은 성공적으로 구문 분석되지만 "0xF3"은 구문 분석하지 않습니다. 에 style 있을 수 있는 유일한 다른 플래그는 및 NumberStyles.AllowTrailingWhite입니다NumberStyles.AllowLeadingWhite. NumberStyles(열거형에는 공백 플래그를 모두 포함하는 복합 숫자 스타일 NumberStyles.HexNumber가 있습니다.)

매개 변수는 provider 또는 개체와 같은 구현입니다 NumberFormatInfoIFormatProviderCultureInfo. 매개 변수는 provider 구문 분석에 사용되는 문화권별 정보를 제공합니다. providernull이면 현재 스레드 문화권이 사용됩니다.

추가 정보

적용 대상

Parse(ReadOnlySpan<Char>, NumberStyles, IFormatProvider)

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의 형식에 대한 문화권별 정보를 제공하는 개체입니다. providernull이면 현재 스레드 문화권이 사용됩니다.

반환

s에 포함된 수와 같은 바이트 값입니다.

구현

적용 대상

Parse(ReadOnlySpan<Byte>, NumberStyles, IFormatProvider)

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

숫자를 지정된 문화권별 형식으로 나타낸 문자열 표현을 해당 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

매개 변수

s
String

변환할 숫자가 포함된 문자열입니다. 이 문자열은 Integer 스타일을 사용하여 해석됩니다.

provider
IFormatProvider

s에 대한 문화권별 구문 분석 정보를 제공하는 개체입니다. providernull이면 현재 스레드 문화권이 사용됩니다.

반환

s에 포함된 수와 같은 바이트 값입니다.

구현

예외

s이(가) null인 경우

s의 형식이 올바르지 않습니다.

sByte.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.
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 선택적 공백입니다.
sign 선택적 양수 기호입니다.
숫자 0에서 9까지의 숫자 시퀀스입니다.

매개 변수는 s 스타일을 사용하여 해석됩니다 Integer . 바이트 값의 10진수 외에도 선행 기호와 함께 선행 및 후행 공백만 허용됩니다. (기호가 있는 경우 양수 기호여야 하거나 메서드가 을 OverflowExceptionthrow합니다.) 에 있을 s수 있는 문화권별 서식 정보와 함께 스타일 요소를 명시적으로 정의하려면 메서드를 Byte.Parse(String, NumberStyles, IFormatProvider) 사용합니다.

s 매개 변수는 에서 제공하는 개체의 서식 정보를 NumberFormatInfo 사용하여 구문 분석됩니다provider. provider 매개 변수는 또는 CultureInfo 개체와 같은 구현입니다 IFormatProviderNumberFormatInfo. 매개 변수는 provider 구문 분석에 사용되는 문화권별 정보를 제공합니다. providernull이면 현재 스레드 문화권이 사용됩니다.

추가 정보

적용 대상

Parse(String, NumberStyles)

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의 형식이 올바르지 않습니다.

sByte.MinValue 보다 작거나 Byte.MaxValue보다 큰 숫자를 나타냅니다.

또는

s에 0이 아닌 소수 자릿수가 포함되어 있습니다.

styleNumberStyles 값이 아닙니다.

또는

styleAllowHexSpecifierHexNumber 값의 조합이 아닙니다.

예제

다음 예제에서는 메서드를 사용하여 값의 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.
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]

또는 가 포함된 경우 style 입니다 AllowHexSpecifier.

[ws]hexdigits[ws]

대괄호 ([ 및 ]) 안의 요소는 선택적 요소입니다. 다음 표에서는 각 요소에 대해 설명합니다.

요소 설명
ws 선택적 공백입니다. 플래그를 포함하는 경우 styles 시작 부분에 공백이 NumberStyles.AllowLeadingWhite 표시되거나 스타일에 플래그가 포함된 경우 의 끝에 표시할 NumberStyles.AllowTrailingWhite 수 있습니다.
$ 문화권별 통화 기호입니다. 문자열의 위치는 현재 문화권의 NumberFormatInfo.CurrencyPositivePattern 속성에 의해 정의됩니다. 플래그가 포함된 경우 style 현재 문화권의 통화 기호가 NumberStyles.AllowCurrencySymbols 나타날 수 있습니다.
sign 선택적 양수 기호입니다. (에 음수 기호가 OverflowException 있으면 메서드가 을 sthrow합니다. 플래그를 포함하는 경우 의 s 시작 부분에 기호가 표시되거나 플래그가 NumberStyles.AllowLeadingSign 포함된 경우 styles 끝에 표시할 NumberStyles.AllowTrailingSignstyle 있습니다.
숫자 0에서 9까지의 숫자 시퀀스입니다.
. 문화권별 소수점 기호입니다. 플래그가 포함된 경우 style 현재 문화권의 소수점 기호가 NumberStyles.AllowDecimalPoints 나타날 수 있습니다.
fractional_digits 숫자 0이 하나 이상 발생합니다. 소수 자릿수는 플래그가 포함된 NumberStyles.AllowDecimalPoint 경우에만 styles 나타날 수 있습니다.
e 값이 지수 표기법으로 표시됨을 나타내는 e 또는 E 문자입니다. 매개 변수는 s 플래그를 포함하는 경우 style 지수 표기법으로 NumberStyles.AllowExponent 숫자를 나타낼 수 있습니다.
hexdigits 0에서 f까지 또는 0부터 F까지의 16진수 숫자 시퀀스입니다.

참고

의 종결 NUL(U+0000) 문자 s 는 인수 값 style 에 관계없이 구문 분석 작업에서 무시됩니다.

10진수만 있는 문자열(스타일에 NumberStyles.None 해당)은 항상 성공적으로 구문 분석됩니다. 나머지 NumberStyles 멤버의 대부분은 이 입력 문자열에 존재할 필요는 없지만 존재할 필요는 없는 요소를 제어합니다. 다음 표에서는 개별 NumberStyles 멤버가 에 s있을 수 있는 요소에 미치는 영향을 나타냅니다.

비 복합 NumberStyles 값 숫자 외에 에서 허용되는 요소
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 이 플래그는 지원되지만 에서 괄호를 사용하면 가 발생OverflowException합니다s.
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

문자 범위를 값으로 구문 분석합니다.

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

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

숫자의 문자열 표현을 해당하는 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
String

변환할 숫자가 포함된 문자열입니다. 이 문자열은 Integer 스타일을 사용하여 해석됩니다.

반환

s에 포함된 수와 같은 바이트 값입니다.

예외

s이(가) null인 경우

s의 형식이 올바르지 않습니다.

sByte.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.
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 선택적 공백입니다.
sign 선택적 양수 또는 음수 기호입니다.
숫자 0에서 9까지의 숫자 시퀀스입니다.

매개 변수는 s 스타일을 사용하여 해석됩니다 NumberStyles.Integer . 바이트 값의 10진수 외에도 선행 기호와 함께 선행 및 후행 공백만 허용됩니다. (기호가 있는 경우 양수 기호여야 하거나 메서드가 을 OverflowExceptionthrow합니다.) 에 s있을 수 있는 스타일 요소를 명시적으로 정의하려면 또는 메서드를 Byte.Parse(String, NumberStyles)Byte.Parse(String, NumberStyles, IFormatProvider) 사용합니다.

s 매개 변수는 현재 시스템 문화권에 대해 초기화된 개체의 NumberFormatInfo 서식 정보를 사용하여 구문 분석됩니다. 자세한 내용은 CurrentInfo를 참조하세요. 다른 문화권의 서식 정보를 사용하여 문자열을 구문 분석하려면 메서드를 Byte.Parse(String, NumberStyles, IFormatProvider) 사용합니다.

추가 정보

적용 대상