SByte.Parse 메서드

정의

숫자의 문자열 표현을 해당하는 8비트 부호 있는 정수로 변환합니다.

오버로드

Parse(String, NumberStyles, IFormatProvider)

지정된 스타일 및 문화권별 형식으로 된 숫자의 문자열 표현을 해당하는 8비트 부호 있는 정수로 변환합니다.

Parse(ReadOnlySpan<Char>, NumberStyles, IFormatProvider)

지정된 스타일 및 문화권별 형식으로 된 숫자의 범위 표현을 해당하는 8비트 부호 있는 정수로 변환합니다.

Parse(ReadOnlySpan<Byte>, NumberStyles, IFormatProvider)

UTF-8자의 범위를 값으로 구문 분석합니다.

Parse(String, IFormatProvider)

지정된 문화권별 형식으로 된 숫자의 문자열 표현을 해당하는 8비트 부호 있는 정수로 변환합니다.

Parse(String)

숫자의 문자열 표현을 해당하는 8비트 부호 있는 정수로 변환합니다.

Parse(ReadOnlySpan<Char>, IFormatProvider)

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

Parse(ReadOnlySpan<Byte>, IFormatProvider)

UTF-8자의 범위를 값으로 구문 분석합니다.

Parse(String, NumberStyles)

지정된 스타일로 된 숫자의 문자열 표현을 해당하는 8비트 부호 있는 정수로 변환합니다.

Parse(String, NumberStyles, IFormatProvider)

Source:
SByte.cs
Source:
SByte.cs
Source:
SByte.cs

중요

이 API는 CLS 규격이 아닙니다.

CLS 대체 규격
System.Int16.Parse(String, NumberStyles, IFormatProvider)

지정된 스타일 및 문화권별 형식으로 된 숫자의 문자열 표현을 해당하는 8비트 부호 있는 정수로 변환합니다.

public:
 static System::SByte Parse(System::String ^ s, System::Globalization::NumberStyles style, IFormatProvider ^ provider);
public:
 static System::SByte Parse(System::String ^ s, System::Globalization::NumberStyles style, IFormatProvider ^ provider) = System::Numerics::INumberBase<System::SByte>::Parse;
[System.CLSCompliant(false)]
public static sbyte Parse (string s, System.Globalization.NumberStyles style, IFormatProvider provider);
public static sbyte Parse (string s, System.Globalization.NumberStyles style, IFormatProvider? provider);
[System.CLSCompliant(false)]
public static sbyte Parse (string s, System.Globalization.NumberStyles style, IFormatProvider? provider);
[<System.CLSCompliant(false)>]
static member Parse : string * System.Globalization.NumberStyles * IFormatProvider -> sbyte
static member Parse : string * System.Globalization.NumberStyles * IFormatProvider -> sbyte
Public Shared Function Parse (s As String, style As NumberStyles, provider As IFormatProvider) As SByte

매개 변수

s
String

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

style
NumberStyles

s에 나타날 수 있는 스타일 요소를 나타내는 열거형 값의 비트 조합입니다. 지정할 일반적인 값은 Integer입니다.

provider
IFormatProvider

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

반환

s 매개 변수에 지정된 숫자에 해당하는 8비트 부호 있는 바이트 값입니다.

구현

특성

예외

styleNumberStyles 값이 아닙니다.

또는

styleAllowHexSpecifierHexNumber의 조합이 아닙니다.

s이(가) null인 경우

sstyle 규격 형식이 아닙니다.

sSByte.MinValue 보다 작거나 SByte.MaxValue보다 큰 숫자를 나타냅니다.

또는

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

예제

다음 예제에서는 메서드를 사용하여 숫자의 Parse(String, NumberStyles, IFormatProvider) 다양한 문자열 표현을 부호 있는 정수 값으로 변환하는 방법을 보여 줍니다.

using System;
using System.Globalization;

public class SByteConversion
{
   NumberFormatInfo provider = NumberFormatInfo.CurrentInfo;

   public static void Main()
   {
      string stringValue;
      NumberStyles style;

      stringValue = "   123   ";
      style = NumberStyles.None;     
      CallParseOperation(stringValue, style);
      
      stringValue = "000,000,123";
      style = NumberStyles.Integer | NumberStyles.AllowThousands;
      CallParseOperation(stringValue, style);
      
      stringValue = "-100";
      style = NumberStyles.AllowLeadingSign;
      CallParseOperation(stringValue, style);
      
      stringValue = "100-";
      style = NumberStyles.AllowLeadingSign;
      CallParseOperation(stringValue, style);
      
      stringValue = "100-";
      style = NumberStyles.AllowTrailingSign;
      CallParseOperation(stringValue, style);
      
      stringValue = "$100";
      style = NumberStyles.AllowCurrencySymbol;
      CallParseOperation(stringValue, style);
      
      style = NumberStyles.Integer;
      CallParseOperation(stringValue, style);
      
      style = NumberStyles.AllowDecimalPoint;
      CallParseOperation("100.0", style);
      
      stringValue = "1e02";
      style = NumberStyles.AllowExponent;
      CallParseOperation(stringValue, style);
      
      stringValue = "(100)";
      style = NumberStyles.AllowParentheses;
      CallParseOperation(stringValue, style);
   }
   
   private static void CallParseOperation(string stringValue, 
                                          NumberStyles style)
   {                                          
      sbyte number;
      
      if (stringValue == null)
         Console.WriteLine("Cannot parse a null string...");
         
      try
      {
         number = sbyte.Parse(stringValue, style);
         Console.WriteLine("SByte.Parse('{0}', {1})) = {2}", 
                           stringValue, style, number);   
      }
      catch (FormatException)
      {
         Console.WriteLine("'{0}' and {1} throw a FormatException", 
                           stringValue, style);   
      }      
      catch (OverflowException)
      {
         Console.WriteLine("'{0}' is outside the range of a signed byte",
                           stringValue);
      }
   }
}
// The example displays the following information to the console:
//       '   123   ' and None throw a FormatException
//       SByte.Parse('000,000,123', Integer, AllowThousands)) = 123
//       SByte.Parse('-100', AllowLeadingSign)) = -100
//       '100-' and AllowLeadingSign throw a FormatException
//       SByte.Parse('100-', AllowTrailingSign)) = -100
//       SByte.Parse('$100', AllowCurrencySymbol)) = 100
//       '$100' and Integer throw a FormatException
//       SByte.Parse('100.0', AllowDecimalPoint)) = 100
//       SByte.Parse('1e02', AllowExponent)) = 100
//       SByte.Parse('(100)', AllowParentheses)) = -100
open System
open System.Globalization

let provider = NumberFormatInfo.CurrentInfo
   
let callParseOperation stringValue (style: NumberStyles) =
    if stringValue = null then
        printfn "Cannot parse a null string..."
    else
        try
            let number = SByte.Parse(stringValue, style)
            printfn $"SByte.Parse('{stringValue}', {style})) = {number}" 
        with
        | :? FormatException ->
            printfn $"'{stringValue}' and {style} throw a FormatException"
        | :? OverflowException ->
            printfn $"'{stringValue}' is outside the range of a signed byte"

[<EntryPoint>]
let main _ =
    let stringValue = "   123   "
    let style = NumberStyles.None     
    callParseOperation stringValue style
    
    let stringValue = "000,000,123"
    let style = NumberStyles.Integer ||| NumberStyles.AllowThousands
    callParseOperation stringValue style
    
    let stringValue = "-100"
    let style = NumberStyles.AllowLeadingSign
    callParseOperation stringValue style
    
    let stringValue = "100-"
    let style = NumberStyles.AllowLeadingSign
    callParseOperation stringValue style
    
    let stringValue = "100-"
    let style = NumberStyles.AllowTrailingSign
    callParseOperation stringValue style
    
    let stringValue = "$100"
    let style = NumberStyles.AllowCurrencySymbol
    callParseOperation stringValue style
    
    let style = NumberStyles.Integer
    callParseOperation stringValue style
    
    let style = NumberStyles.AllowDecimalPoint
    callParseOperation "100.0" style
    
    let stringValue = "1e02"
    let style = NumberStyles.AllowExponent
    callParseOperation stringValue style
    
    let stringValue = "(100)"
    let style = NumberStyles.AllowParentheses
    callParseOperation stringValue style
    0

// The example displays the following information to the console:
//       '   123   ' and None throw a FormatException
//       SByte.Parse('000,000,123', Integer, AllowThousands)) = 123
//       SByte.Parse('-100', AllowLeadingSign)) = -100
//       '100-' and AllowLeadingSign throw a FormatException
//       SByte.Parse('100-', AllowTrailingSign)) = -100
//       SByte.Parse('$100', AllowCurrencySymbol)) = 100
//       '$100' and Integer throw a FormatException
//       SByte.Parse('100.0', AllowDecimalPoint)) = 100
//       SByte.Parse('1e02', AllowExponent)) = 100
//       SByte.Parse('(100)', AllowParentheses)) = -100
Imports System.Globalization

Module modMain
   Public Sub Main()
      Dim byteString As String 
      
      byteString = " 123"
      ParseString(byteString, NumberStyles.None)
      ParseString(byteString, NumberStyles.Integer)
      
      byteString = "3A"
      ParseString(byteString, NumberStyles.AllowHexSpecifier) 
      
      byteString = "21"
      ParseString(byteString, NumberStyles.Integer)
      ParseString(byteString, NumberStyles.AllowHexSpecifier)
      
      byteString = "-22"
      ParseString(byteString, NumberStyles.Integer)
      ParseString(byteString, NumberStyles.AllowParentheses)
      
      byteString = "(45)"
      ParseString(byteString, NumberStyles.AllowParentheses)
     
      byteString = "000,000,056"
      ParseString(byteString, NumberStyles.Integer)
      ParseString(byteString, NumberStyles.Integer Or NumberStyles.AllowThousands)
   End Sub
   
   Private Sub ParseString(value As String, style As NumberStyles)
      Dim number As SByte
      
      If value Is Nothing Then Console.WriteLine("Cannot parse a null string...") 
      
      Try
         number = SByte.Parse(value, style, NumberFormatInfo.CurrentInfo)
         Console.WriteLine("SByte.Parse('{0}', {1}) = {2}", value, style, number)   
      Catch e As FormatException
         Console.WriteLine("'{0}' and {1} throw a FormatException", value, style)   
      Catch e As OverflowException
         Console.WriteLine("'{0}' is outside the range of a signed byte",
                           value)
      End Try     
   End Sub
End Module
' The example displays the following information to the console:
'       ' 123' and None throw a FormatException
'       SByte.Parse(" 123", Integer)) = 123
'       SByte.Parse("3A", AllowHexSpecifier)) = 58
'       SByte.Parse("21", Integer)) = 21
'       SByte.Parse("21", AllowHexSpecifier)) = 33
'       SByte.Parse("-22", Integer)) = -22
'       '-22' and AllowParentheses throw a FormatException
'       SByte.Parse("(45)", AllowParentheses)) = -45
'       '000,000,056' and Integer throw a FormatException
'       SByte.Parse("000,000,056", Integer, AllowThousands)) = 56

설명

매개 변수는 style 구문 분석 작업이 성공하기 위해 매개 변수에 s 허용되는 스타일 요소(예: 공백 또는 양수 또는 음수 기호)를 정의합니다. 열거형의 비트 플래그 NumberStyles 조합이어야 합니다.

의 값 style에 따라 매개 변수에는 s 다음 요소가 포함될 수 있습니다.

[ws] [$][sign]digits[.fractional_digits][E[sign]exponential_digits][ws]

가 포함된 AllowHexSpecifier경우 style 매개 변수에는 s 다음 요소가 포함될 수 있습니다.

[ws] hexdigits[ws]

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

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

참고

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

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

비 복합 NumberStyles 숫자 외에 에서 s 허용되는 요소
NumberStyles.None 10진수에만 해당합니다.
NumberStyles.AllowDecimalPoint 소수점(.) 및 fractional_digits 요소입니다. 그러나 스타일에 플래그가 NumberStyles.AllowExponent 포함되지 않은 경우 fractional_digits 하나 이상의 0자리 숫자로만 구성되어야 합니다. 그렇지 않으면 이 OverflowException throw됩니다.
NumberStyles.AllowExponent exponential_digits 함께 지수 표기법을 나타내는 "e" 또는 "E" 문자입니다.
NumberStyles.AllowLeadingWhite 의 시작 부분에 있는 ws 요소입니다 s.
NumberStyles.AllowTrailingWhite 의 끝에 있는 ws 요소입니다 s.
NumberStyles.AllowLeadingSign 숫자 앞의 양수 기호 입니다.
NumberStyles.AllowTrailingSign 숫자 뒤의 양수 기호 입니다.
NumberStyles.AllowParentheses 숫자 앞과 뒤를 괄호 괄호로 하여 음수 값을 나타냅니다.
NumberStyles.AllowThousands 그룹 구분 기호(,) 요소입니다. 그룹 구분 기호는 에 s나타날 수 있지만 앞에는 0자리 이상의 숫자만 있어야 합니다.
NumberStyles.AllowCurrencySymbol currency($) 요소입니다.

플래그를 NumberStyles.AllowHexSpecifier 사용하는 s 경우 은 16진수 값이어야 합니다. 유효한 16진수 숫자는 0-9, a-f 및 A-F입니다. 함께 결합할 수 있는 유일한 다른 플래그는 및 NumberStyles.AllowTrailingWhite입니다NumberStyles.AllowLeadingWhite. (열거형에는 NumberStyles 공백 플래그를 모두 포함하는 복합 숫자 스타일 NumberStyles.HexNumber이 포함됩니다.)

참고

매개 변수가 s 16진수의 문자열 표현인 경우 16진수로 구분하는 장식(예: 0x 또는 &h)이 앞에 올 수 없습니다. 이로 인해 구문 분석 작업이 예외를 throw합니다.

16진수를 나타내는 경우 s 메서드는 Parse(String, NumberStyles) 바이트의 상위 비트를 부호 비트로 해석합니다.

provider 매개 변수는 메서드가 IFormatProviderGetFormat 형식에 NumberFormatInfo 대한 문화권별 정보를 제공하는 개체를 반환하는 구현입니다s. 매개 변수를 사용하여 provider 구문 분석 작업에 사용자 지정 서식 정보를 제공하는 세 가지 방법이 있습니다.

  • 서식 정보를 제공하는 실제 NumberFormatInfo 개체를 전달할 수 있습니다. (의 GetFormat 구현은 단순히 자체를 반환합니다.)

  • 서식을 CultureInfo 사용할 문화권을 지정하는 개체를 전달할 수 있습니다. 해당 속성은 NumberFormat 서식 정보를 제공합니다.

  • 사용자 지정 IFormatProvider 구현을 전달할 수 있습니다. 해당 메서드는 GetFormat 서식 정보를 제공하는 개체를 NumberFormatInfo 인스턴스화하고 반환해야 합니다.

가 이 nullNumberFormatInfoprovider 현재 문화권의 개체가 사용됩니다.

적용 대상

Parse(ReadOnlySpan<Char>, NumberStyles, IFormatProvider)

Source:
SByte.cs
Source:
SByte.cs
Source:
SByte.cs

중요

이 API는 CLS 규격이 아닙니다.

지정된 스타일 및 문화권별 형식으로 된 숫자의 범위 표현을 해당하는 8비트 부호 있는 정수로 변환합니다.

public static sbyte Parse (ReadOnlySpan<char> s, System.Globalization.NumberStyles style = System.Globalization.NumberStyles.Integer, IFormatProvider? provider = default);
[System.CLSCompliant(false)]
public static sbyte Parse (ReadOnlySpan<char> s, System.Globalization.NumberStyles style = System.Globalization.NumberStyles.Integer, IFormatProvider provider = default);
[System.CLSCompliant(false)]
public static sbyte Parse (ReadOnlySpan<char> s, System.Globalization.NumberStyles style = System.Globalization.NumberStyles.Integer, IFormatProvider? provider = default);
static member Parse : ReadOnlySpan<char> * System.Globalization.NumberStyles * IFormatProvider -> sbyte
[<System.CLSCompliant(false)>]
static member Parse : ReadOnlySpan<char> * System.Globalization.NumberStyles * IFormatProvider -> sbyte
Public Shared Function Parse (s As ReadOnlySpan(Of Char), Optional style As NumberStyles = System.Globalization.NumberStyles.Integer, Optional provider As IFormatProvider = Nothing) As SByte

매개 변수

s
ReadOnlySpan<Char>

변환할 숫자를 나타내는 문자를 포함하는 범위입니다. style로 지정된 스타일을 사용하여 이 범위를 해석합니다.

style
NumberStyles

s에 나타날 수 있는 스타일 요소를 나타내는 열거형 값의 비트 조합입니다. 지정할 일반적인 값은 Integer입니다.

provider
IFormatProvider

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

반환

s 매개 변수에 지정된 숫자에 해당하는 8비트 부호 있는 바이트 값입니다.

구현

특성

적용 대상

Parse(ReadOnlySpan<Byte>, NumberStyles, IFormatProvider)

Source:
SByte.cs
Source:
SByte.cs

UTF-8자의 범위를 값으로 구문 분석합니다.

public static sbyte Parse (ReadOnlySpan<byte> utf8Text, System.Globalization.NumberStyles style = System.Globalization.NumberStyles.Integer, IFormatProvider? provider = default);
static member Parse : ReadOnlySpan<byte> * System.Globalization.NumberStyles * IFormatProvider -> sbyte
Public Shared Function Parse (utf8Text As ReadOnlySpan(Of Byte), Optional style As NumberStyles = System.Globalization.NumberStyles.Integer, Optional provider As IFormatProvider = Nothing) As SByte

매개 변수

utf8Text
ReadOnlySpan<Byte>

구문 분석할 UTF-8 문자의 범위입니다.

style
NumberStyles

utf8Text있을 수 있는 숫자 스타일의 비트 조합입니다.

provider
IFormatProvider

utf8Text에 대한 문화권별 서식 정보를 제공하는 개체입니다.

반환

구문 분석의 결과입니다 utf8Text.

구현

적용 대상

Parse(String, IFormatProvider)

Source:
SByte.cs
Source:
SByte.cs
Source:
SByte.cs

중요

이 API는 CLS 규격이 아닙니다.

CLS 대체 규격
System.Int16.Parse(String)

지정된 문화권별 형식으로 된 숫자의 문자열 표현을 해당하는 8비트 부호 있는 정수로 변환합니다.

public:
 static System::SByte Parse(System::String ^ s, IFormatProvider ^ provider);
public:
 static System::SByte Parse(System::String ^ s, IFormatProvider ^ provider) = IParsable<System::SByte>::Parse;
[System.CLSCompliant(false)]
public static sbyte Parse (string s, IFormatProvider provider);
public static sbyte Parse (string s, IFormatProvider? provider);
[System.CLSCompliant(false)]
public static sbyte Parse (string s, IFormatProvider? provider);
[<System.CLSCompliant(false)>]
static member Parse : string * IFormatProvider -> sbyte
static member Parse : string * IFormatProvider -> sbyte
Public Shared Function Parse (s As String, provider As IFormatProvider) As SByte

매개 변수

s
String

변환할 숫자를 나타내는 문자열입니다. 이 문자열은 Integer 스타일을 사용하여 해석됩니다.

provider
IFormatProvider

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

반환

s에 지정된 숫자에 해당하는 8비트 부호 있는 정수입니다.

구현

특성

예외

s이(가) null인 경우

s가 올바른 형식이 아닙니다.

sSByte.MinValue 보다 작거나 SByte.MaxValue보다 큰 숫자를 나타냅니다.

예제

다음 예제에서는 타일(~)을 음수 기호로 정의하는 사용자 지정 NumberFormatInfo 개체를 정의합니다. 그런 다음 이 사용자 지정 NumberFormatInfo 개체와 고정 문화권을 나타내는 개체를 CultureInfo 사용하여 여러 숫자 문자열을 구문 분석합니다.

using System;
using System.Globalization;

public class Example
{
   public static void Main()
   {
      NumberFormatInfo nf = new NumberFormatInfo();
      nf.NegativeSign = "~"; 
      
      string[] values = { "-103", "+12", "~16", "  1", "~255" };
      IFormatProvider[] providers = { nf, CultureInfo.InvariantCulture };
      
      foreach (IFormatProvider provider in providers)
      {
         Console.WriteLine("Conversions using {0}:", ((object) provider).GetType().Name);
         foreach (string value in values)
         {
            try {
               Console.WriteLine("   Converted '{0}' to {1}.", 
                                 value, SByte.Parse(value, provider));
            }                     
            catch (FormatException) {
               Console.WriteLine("   Unable to parse '{0}'.", value);   
            }
            catch (OverflowException) {
               Console.WriteLine("   '{0}' is out of range of the SByte type.", value);         
            }
         }
      }      
   }
}
// The example displays the following output:
//       Conversions using NumberFormatInfo:
//          Unable to parse '-103'.
//          Converted '+12' to 12.
//          Converted '~16' to -16.
//          Converted '  1' to 1.
//          '~255' is out of range of the SByte type.
//       Conversions using CultureInfo:
//          Converted '-103' to -103.
//          Converted '+12' to 12.
//          Unable to parse '~16'.
//          Converted '  1' to 1.
//          Unable to parse '~255'.
open System
open System.Globalization

let nf = NumberFormatInfo()
nf.NegativeSign <- "~" 

let values = [| "-103"; "+12"; "~16"; "  1"; "~255" |]
let providers: IFormatProvider[] = [| nf; CultureInfo.InvariantCulture |]

for provider in providers do
    printfn $"Conversions using {(box provider).GetType().Name}:"
    for value in values do
        try
            printfn $"   Converted '{value}' to {SByte.Parse(value, provider)}."
        with
        | :? FormatException ->
            printfn $"   Unable to parse '{value}'."
        | :? OverflowException ->
            printfn $"   '{value}' is out of range of the SByte type."

// The example displays the following output:
//       Conversions using NumberFormatInfo:
//          Unable to parse '-103'.
//          Converted '+12' to 12.
//          Converted '~16' to -16.
//          Converted '  1' to 1.
//          '~255' is out of range of the SByte type.
//       Conversions using CultureInfo:
//          Converted '-103' to -103.
//          Converted '+12' to 12.
//          Unable to parse '~16'.
//          Converted '  1' to 1.
//          Unable to parse '~255'.
Imports System.Globalization

Module Example
   Public Sub Main()
      Dim nf As New NumberFormatInfo()
      nf.NegativeSign = "~" 
      
      Dim values() As String = { "-103", "+12", "~16", "  1", "~255" }
      Dim providers() As IFormatProvider = { nf, CultureInfo.InvariantCulture }
      
      For Each provider As IFormatProvider In providers
         Console.WriteLine("Conversions using {0}:", CObj(provider).GetType().Name)
         For Each value As String In values
            Try
               Console.WriteLine("   Converted '{0}' to {1}.", _
                                 value, SByte.Parse(value, provider))
            Catch e As FormatException
               Console.WriteLine("   Unable to parse '{0}'.", value)   
            Catch e As OverflowException
               Console.WriteLine("   '{0}' is out of range of the SByte type.", value)         
            End Try
         Next
      Next      
   End Sub
End Module
' The example displays '
'       Conversions using NumberFormatInfo:
'          Unable to parse '-103'.
'          Converted '+12' to 12.
'          Converted '~16' to -16.
'          Converted '  1' to 1.
'          '~255' is out of range of the SByte type.
'       Conversions using CultureInfo:
'          Converted '-103' to -103.
'          Converted '+12' to 12.
'          Unable to parse '~16'.
'          Converted '  1' to 1.
'          Unable to parse '~255'.

설명

매개 변수에는 s 다음과 같은 여러 양식이 포함됩니다.

[ws] [sign] digits[ws]

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

요소 설명
ws 선택적 공백입니다.
sign 선택적 기호입니다.
숫자 0에서 9까지의 숫자 시퀀스입니다.

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

provider 매개 변수는 메서드가 IFormatProviderGetFormat 형식에 NumberFormatInfo 대한 문화권별 정보를 제공하는 개체를 반환하는 구현입니다s. 매개 변수를 사용하여 provider 구문 분석 작업에 사용자 지정 서식 정보를 제공하는 세 가지 방법이 있습니다.

  • 서식 정보를 제공하는 실제 NumberFormatInfo 개체를 전달할 수 있습니다. (의 GetFormat 구현은 단순히 자체를 반환합니다.)

  • 서식을 CultureInfo 사용할 문화권을 지정하는 개체를 전달할 수 있습니다. 해당 속성은 NumberFormat 서식 정보를 제공합니다.

  • 사용자 지정 IFormatProvider 구현을 전달할 수 있습니다. 해당 메서드는 GetFormat 서식 정보를 제공하는 개체를 NumberFormatInfo 인스턴스화하고 반환해야 합니다.

가 이 nullNumberFormatInfoprovider 현재 문화권의 개체가 사용됩니다.

추가 정보

적용 대상

Parse(String)

Source:
SByte.cs
Source:
SByte.cs
Source:
SByte.cs

중요

이 API는 CLS 규격이 아닙니다.

CLS 대체 규격
System.Int16.Parse(String)

숫자의 문자열 표현을 해당하는 8비트 부호 있는 정수로 변환합니다.

public:
 static System::SByte Parse(System::String ^ s);
[System.CLSCompliant(false)]
public static sbyte Parse (string s);
public static sbyte Parse (string s);
[<System.CLSCompliant(false)>]
static member Parse : string -> sbyte
static member Parse : string -> sbyte
Public Shared Function Parse (s As String) As SByte

매개 변수

s
String

변환할 숫자를 나타내는 문자열입니다. 이 문자열은 Integer 스타일을 사용하여 해석됩니다.

반환

s 매개 변수에 있는 숫자에 해당하는 8비트 부호 있는 정수입니다.

특성

예외

s이(가) null인 경우

s가 선택적 부호와 숫자 시퀀스(0~9)로 구성되어 있지 않습니다.

sSByte.MinValue 보다 작거나 SByte.MaxValue보다 큰 숫자를 나타냅니다.

예제

다음 예제에서는 메서드를 사용 하 여 서명 된 바이트 값으로 문자열 값을 변환 하는 Parse 방법을 보여 줍니다. 그러면 결과 서명된 바이트 값이 콘솔에 표시됩니다.

// Define an array of numeric strings.
string[] values = { "-16", "  -3", "+ 12", " +12 ", "  12  ",
                    "+120", "(103)", "192", "-160" };
                           
// Parse each string and display the result.
foreach (string value in values)
{
   try {
      Console.WriteLine("Converted '{0}' to the SByte value {1}.",
                        value, SByte.Parse(value));
   }
   catch (FormatException) {
      Console.WriteLine("'{0}' cannot be parsed successfully by SByte type.",
                        value);
   }                              
   catch (OverflowException) {
      Console.WriteLine("'{0}' is out of range of the SByte type.",
                        value);
   }                                                                        
}
// The example displays the following output:
//       Converted '-16' to the SByte value -16.
//       Converted '  -3' to the SByte value -3.
//       '+ 12' cannot be parsed successfully by SByte type.
//       Converted ' +12 ' to the SByte value 12.
//       Converted '  12  ' to the SByte value 12.
//       Converted '+120' to the SByte value 120.
//       '(103)' cannot be parsed successfully by SByte type.
//       '192' is out of range of the SByte type.
//       '-160' is out of range of the SByte type.
open System

// Define an array of numeric strings.
let values = 
    [| "-16"; "  -3"; "+ 12"; " +12 "; "  12  "
       "+120"; "(103)"; "192"; "-160" |]
                            
// Parse each string and display the result.
for value in values do
    try
        printfn $"Converted '{value}' to the SByte value {SByte.Parse value}."
    with
    | :? FormatException ->
        printfn $"'{value}' cannot be parsed successfully by SByte type."
    | :? OverflowException ->
        printfn $"'{value}' is out of range of the SByte type."
        
// The example displays the following output:
//       Converted '-16' to the SByte value -16.
//       Converted '  -3' to the SByte value -3.
//       '+ 12' cannot be parsed successfully by SByte type.
//       Converted ' +12 ' to the SByte value 12.
//       Converted '  12  ' to the SByte value 12.
//       Converted '+120' to the SByte value 120.
//       '(103)' cannot be parsed successfully by SByte type.
//       '192' is out of range of the SByte type.
//       '-160' is out of range of the SByte type.
' Define an array of numeric strings.
Dim values() As String = { "-16", "  -3", "+ 12", " +12 ", "  12  ", _
                           "+120", "(103)", "192", "-160" }
                           
' Parse each string and display the result.
For Each value As String In values
   Try
      Console.WriteLine("Converted '{0}' to the SByte value {1}.", _
                        value, SByte.Parse(value))
   Catch e As FormatException
      Console.WriteLine("'{0}' cannot be parsed successfully by SByte type.", _
                        value)
   Catch e As OverflowException
      Console.WriteLine("'{0}' is out of range of the SByte type.", _
                        value)
   End Try                                                                        
Next        
' The example displays the following output:
'       Converted '-16' to the SByte value -16.
'       Converted '  -3' to the SByte value -3.
'       '+ 12' cannot be parsed successfully by SByte type.
'       Converted ' +12 ' to the SByte value 12.
'       Converted '  12  ' to the SByte value 12.
'       Converted '+120' to the SByte value 120.
'       '(103)' cannot be parsed successfully by SByte type.
'       '192' is out of range of the SByte type.
'       '-160' is out of range of the SByte type.

설명

매개 변수에는 s 다음과 같은 여러 양식이 포함됩니다.

[ws] [sign] digits[ws]

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

요소 설명
ws 선택적 공백입니다.
sign 선택적 기호입니다.
숫자 0에서 9까지의 숫자 시퀀스입니다.

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

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

추가 정보

적용 대상

Parse(ReadOnlySpan<Char>, IFormatProvider)

Source:
SByte.cs
Source:
SByte.cs
Source:
SByte.cs

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

public:
 static System::SByte Parse(ReadOnlySpan<char> s, IFormatProvider ^ provider) = ISpanParsable<System::SByte>::Parse;
public static sbyte Parse (ReadOnlySpan<char> s, IFormatProvider? provider);
static member Parse : ReadOnlySpan<char> * IFormatProvider -> sbyte
Public Shared Function Parse (s As ReadOnlySpan(Of Char), provider As IFormatProvider) As SByte

매개 변수

s
ReadOnlySpan<Char>

구문 분석할 문자의 범위입니다.

provider
IFormatProvider

s에 대한 문화권별 서식 정보를 제공하는 개체입니다.

반환

구문 분석의 결과입니다 s.

구현

적용 대상

Parse(ReadOnlySpan<Byte>, IFormatProvider)

Source:
SByte.cs
Source:
SByte.cs

UTF-8자의 범위를 값으로 구문 분석합니다.

public:
 static System::SByte Parse(ReadOnlySpan<System::Byte> utf8Text, IFormatProvider ^ provider) = IUtf8SpanParsable<System::SByte>::Parse;
public static sbyte Parse (ReadOnlySpan<byte> utf8Text, IFormatProvider? provider);
static member Parse : ReadOnlySpan<byte> * IFormatProvider -> sbyte
Public Shared Function Parse (utf8Text As ReadOnlySpan(Of Byte), provider As IFormatProvider) As SByte

매개 변수

utf8Text
ReadOnlySpan<Byte>

구문 분석할 UTF-8 문자의 범위입니다.

provider
IFormatProvider

utf8Text에 대한 문화권별 서식 정보를 제공하는 개체입니다.

반환

구문 분석의 결과입니다 utf8Text.

구현

적용 대상

Parse(String, NumberStyles)

Source:
SByte.cs
Source:
SByte.cs
Source:
SByte.cs

중요

이 API는 CLS 규격이 아닙니다.

CLS 대체 규격
System.Int16.Parse(String)

지정된 스타일로 된 숫자의 문자열 표현을 해당하는 8비트 부호 있는 정수로 변환합니다.

public:
 static System::SByte Parse(System::String ^ s, System::Globalization::NumberStyles style);
[System.CLSCompliant(false)]
public static sbyte Parse (string s, System.Globalization.NumberStyles style);
public static sbyte Parse (string s, System.Globalization.NumberStyles style);
[<System.CLSCompliant(false)>]
static member Parse : string * System.Globalization.NumberStyles -> sbyte
static member Parse : string * System.Globalization.NumberStyles -> sbyte
Public Shared Function Parse (s As String, style As NumberStyles) As SByte

매개 변수

s
String

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

style
NumberStyles

s에 나타날 수 있는 스타일 요소를 나타내는 열거형 값의 비트 조합입니다. 지정할 일반적인 값은 Integer입니다.

반환

s에 지정된 숫자에 해당하는 8비트 부호 있는 정수입니다.

특성

예외

s이(가) null인 경우

sstyle 규격 형식이 아닙니다.

sSByte.MinValue 보다 작거나 SByte.MaxValue보다 큰 숫자를 나타냅니다.

또는

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

styleNumberStyles 값이 아닙니다.

또는

styleAllowHexSpecifierHexNumber 값의 조합이 아닙니다.

예제

다음 예제에서는 메서드를 사용하여 값의 SByte 문자열 표현을 Parse(String, NumberStyles) 구문 분석합니다. 예제의 현재 문화권은 en-US입니다.

using System;
using System.Globalization;

public class Example
{
   public static void Main()
   {
      NumberStyles style;
      sbyte number;

      // Parse value with no styles allowed.
      string[] values1 = { " 121 ", "121", "-121" };
      style = NumberStyles.None;
      Console.WriteLine("Styles: {0}", style.ToString());
      foreach (string value in values1)
      {
         try {
            number = SByte.Parse(value, style);
            Console.WriteLine("   Converted '{0}' to {1}.", value, number);
         }   
         catch (FormatException) {
            Console.WriteLine("   Unable to parse '{0}'.", value);
         }
      }
      Console.WriteLine();
            
      // Parse value with trailing sign.
      style = NumberStyles.Integer | NumberStyles.AllowTrailingSign;
      string[] values2 = { " 103+", " 103 +", "+103", "(103)", "   +103  " };
      Console.WriteLine("Styles: {0}", style.ToString());
      foreach (string value in values2)
      {
         try {
            number = SByte.Parse(value, style);
            Console.WriteLine("   Converted '{0}' to {1}.", value, number);
         }   
         catch (FormatException) {
            Console.WriteLine("   Unable to parse '{0}'.", value);
         }      
         catch (OverflowException) {
            Console.WriteLine("   '{0}' is out of range of the SByte type.", value);         
         }
      }      
      Console.WriteLine();
   }
}
// The example displays the following output:
//       Styles: None
//          Unable to parse ' 121 '.
//          Converted '121' to 121.
//          Unable to parse '-121'.
//       
//       Styles: Integer, AllowTrailingSign
//          Converted ' 103+' to 103.
//          Converted ' 103 +' to 103.
//          Converted '+103' to 103.
//          Unable to parse '(103)'.
//          Converted '   +103  ' to 103.
open System
open System.Globalization

// Parse value with no styles allowed.
let values1 = [| " 121 "; "121"; "-121" |]
let style = NumberStyles.None
printfn $"Styles: {style}"
for value in values1 do
    try
        let number = SByte.Parse(value, style)
        printfn $"   Converted '{value}' to {number}."
    with :? FormatException ->
        printfn $"   Unable to parse '{value}'."
printfn ""
            
// Parse value with trailing sign.
let style2 = NumberStyles.Integer ||| NumberStyles.AllowTrailingSign
let values2 = [| " 103+"; " 103 +"; "+103"; "(103)"; "   +103  " |]
printfn $"Styles: {style2}"
for value in values2 do
    try
        let number = SByte.Parse(value, style2)
        printfn $"   Converted '{value}' to {number}."
    with 
    | :? FormatException ->
        printfn $"   Unable to parse '{value}'."
    | :? OverflowException ->
        printfn $"   '{value}' is out of range of the SByte type."         
printfn ""
// The example displays the following output:
//       Styles: None
//          Unable to parse ' 121 '.
//          Converted '121' to 121.
//          Unable to parse '-121'.
//       
//       Styles: Integer, AllowTrailingSign
//          Converted ' 103+' to 103.
//          Converted ' 103 +' to 103.
//          Converted '+103' to 103.
//          Unable to parse '(103)'.
//          Converted '   +103  ' to 103.
Imports System.Globalization

Module Example
   Public Sub Main()
      Dim style As NumberStyles
      Dim number As SByte

      ' Parse value with no styles allowed.
      Dim values1() As String = { " 121 ", "121", "-121" }
      style = NumberStyles.None
      Console.WriteLine("Styles: {0}", style.ToString())
      For Each value As String In values1
         Try
            number = SByte.Parse(value, style)
            Console.WriteLine("   Converted '{0}' to {1}.", value, number)
         Catch e As FormatException
            Console.WriteLine("   Unable to parse '{0}'.", value)   
         End Try
      Next
      Console.WriteLine()
            
      ' Parse value with trailing sign.
      style = NumberStyles.Integer Or NumberStyles.AllowTrailingSign
      Dim values2() As String = { " 103+", " 103 +", "+103", "(103)", "   +103  " }
      Console.WriteLine("Styles: {0}", style.ToString())
      For Each value As String In values2
         Try
            number = SByte.Parse(value, style)
            Console.WriteLine("   Converted '{0}' to {1}.", value, number)
         Catch e As FormatException
            Console.WriteLine("   Unable to parse '{0}'.", value)   
         Catch e As OverflowException
            Console.WriteLine("   '{0}' is out of range of the SByte type.", value)         
         End Try
      Next      
      Console.WriteLine()
   End Sub
End Module
' The example displays the following output:
'       Styles: None
'          Unable to parse ' 121 '.
'          Converted '121' to 121.
'          Unable to parse '-121'.
'       
'       Styles: Integer, AllowTrailingSign
'          Converted ' 103+' to 103.
'          Converted ' 103 +' to 103.
'          Converted '+103' to 103.
'          Unable to parse '(103)'.
'          Converted '   +103  ' to 103.

설명

매개 변수는 style 구문 분석 작업이 성공하기 위해 매개 변수에 s 허용되는 스타일 요소(예: 공백 또는 양수 또는 음수 기호)를 정의합니다. 열거형의 비트 플래그 NumberStyles 조합이어야 합니다.

의 값 style에 따라 매개 변수에 s 다음 요소가 포함될 수 있습니다.

[ws] [$][sign]digits[.fractional_digits][E[sign]exponential_digits][ws]

가 포함된 NumberStyles.AllowHexSpecifier경우 style 매개 변수에 s 다음 요소가 포함될 수 있습니다.

[ws] hexdigits[ws]

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

요소 설명
ws 선택적 공백입니다. 플래그를 포함하는 경우 style 의 시작 부분에 s 공백이 NumberStyles.AllowLeadingWhite 표시될 수 있으며 스타일에 플래그가 포함되어 NumberStyles.AllowTrailingWhite 있으면 의 s 끝에 표시될 수 있습니다.
$ 문화권별 통화 기호입니다. 문자열의 위치는 현재 문화권의 NumberFormatInfo.CurrencyPositivePattern 속성에 의해 정의됩니다. 플래그가 포함된 경우 style 현재 문화권의 통화 기호가 NumberStyles.AllowCurrencySymbols 나타날 수 있습니다.
sign 선택적 기호입니다. 플래그가 포함된 경우 style 의 시작 부분에 s 기호가 NumberStyles.AllowLeadingSign 표시되고 플래그가 포함된 NumberStyles.AllowTrailingSign 경우 styles 끝에 표시할 수 있습니다. 플래그가 포함된 NumberStyles.AllowParentheses 경우 style 괄호를 사용하여 s 음수 값을 나타낼 수 있습니다.
숫자 0에서 9까지의 숫자 시퀀스입니다.
. 문화권별 소수점 기호입니다. 플래그가 포함된 경우 style 현재 문화권의 소수점 기호가 NumberStyles.AllowDecimalPoints 나타날 수 있습니다.
fractional_digits 플래그가 포함된 NumberStyles.AllowExponent 경우 숫자 0-9가 하나 이상 발생하거나, 그렇지 않은 경우 style 숫자 0이 하나 이상 발생합니다. 소수 자릿수는 플래그가 포함된 경우에만 styles 표시할 NumberStyles.AllowDecimalPoint 수 있습니다.
E 값이 지수(과학적) 표기법으로 표시됨을 나타내는 "e" 또는 "E" 문자입니다. 플래그가 포함된 경우 style 매개 변수는 s 지수 표기법으로 NumberStyles.AllowExponent 숫자를 나타낼 수 있습니다.
exponential_digits 숫자 0-9가 하나 이상 발생합니다. 플래그가 포함된 경우 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 요소입니다. 그러나 플래그가 NumberStyles.AllowExponent 포함되지 않은 경우 stylefractional_digits 하나 이상의 0자리 숫자로만 구성되어야 합니다. 그렇지 않으면 이 OverflowException throw됩니다.
NumberStyles.AllowExponent exponential_digits 함께 지수 표기법을 나타내는 "e" 또는 "E" 문자입니다.
NumberStyles.AllowLeadingWhite 의 시작 부분에 있는 ws 요소입니다 s.
NumberStyles.AllowTrailingWhite 의 끝에 있는 ws 요소입니다 s.
NumberStyles.AllowLeadingSign 숫자 앞의 양수 기호 입니다.
NumberStyles.AllowTrailingSign 숫자 뒤의 양수 기호 입니다.
NumberStyles.AllowParentheses 숫자 값을 묶는 괄호 형식의 기호 요소입니다.
NumberStyles.AllowThousands 그룹 구분 기호(,) 요소입니다. 그룹 구분 기호는 에 s표시될 수 있지만 앞에 0개 이상의 숫자만 있어야 합니다.
NumberStyles.AllowCurrencySymbol currency($) 요소입니다.

플래그를 NumberStyles.AllowHexSpecifier 사용하는 s 경우 은 16진수 값이어야 합니다. 유효한 16진수는 0-9, a-f 및 A-F입니다. "0x"와 같은 접두사는 지원되지 않으며 구문 분석 작업이 실패합니다. 에 포함 style 할 수 있는 유일한 다른 플래그는 및 NumberStyles.AllowTrailingWhite입니다NumberStyles.AllowLeadingWhite. (열거형에는 NumberStyles 공백 플래그를 모두 포함하는 복합 숫자 스타일 NumberStyles.HexNumber가 포함됩니다.)

참고

매개 변수가 s 16진수의 문자열 표현인 경우 16진수로 구분하는 장식(예: 0x 또는 &h)이 앞에 올 수 없습니다. 이렇게 하면 구문 분석 작업이 예외를 throw합니다.

16진수를 나타내는 경우 s 메서드는 Parse(String, NumberStyles) 바이트의 상위 비트를 부호 비트로 해석합니다.

매개 변수는 s 현재 시스템 문화권에 대해 초기화된 개체의 NumberFormatInfo 서식 정보를 사용하여 구문 분석됩니다. 다른 문화권의 서식 정보를 사용하려면 오버로드를 호출합니다 Parse(String, NumberStyles, IFormatProvider) .

추가 정보

적용 대상