NumberStyles 열거형

정의

정수 및 부동 소수점 숫자 형식의 ParseTryParse 메서드에 전달되는 숫자 문자열에서 사용할 수 있는 스타일을 결정합니다.

이 열거형은 멤버 값의 비트 조합을 지원합니다.

public enum class NumberStyles
[System.Flags]
public enum NumberStyles
[System.Flags]
[System.Serializable]
public enum NumberStyles
[System.Flags]
[System.Serializable]
[System.Runtime.InteropServices.ComVisible(true)]
public enum NumberStyles
[<System.Flags>]
type NumberStyles = 
[<System.Flags>]
[<System.Serializable>]
type NumberStyles = 
[<System.Flags>]
[<System.Serializable>]
[<System.Runtime.InteropServices.ComVisible(true)>]
type NumberStyles = 
Public Enum NumberStyles
상속
NumberStyles
특성

필드

AllowBinarySpecifier 1024

숫자 문자열이 이진 값을 나타낸다는 것을 나타냅니다. 유효한 이진 값에는 숫자 0과 1이 포함됩니다. 이 스타일을 사용하여 구문 분석되는 문자열은 접두사를 사용하지 않습니다. 0b 를 사용할 수 없습니다. 스타일을 사용하여 AllowBinarySpecifier 구문 분석되는 문자열은 항상 이진 값으로 해석됩니다. AllowBinarySpecifier와 함께 사용할 수 있는 플래그는 AllowLeadingWhiteAllowTrailingWhite뿐입니다. NumberStyles 열거형에는 이러한 세 플래그로 구성된 복합 스타일인 BinaryNumber가 포함됩니다.

AllowCurrencySymbol 256

숫자 문자열에 통화 기호가 포함될 수 있음을 나타냅니다. 유효한 통화 기호는 CurrencySymbol 속성으로 결정됩니다.

AllowDecimalPoint 32

숫자 문자열에 소수점이 있을 수 있음을 나타냅니다. NumberStyles 값에 AllowCurrencySymbol 플래그가 포함되고 구문 분석된 문자열에 통화 기호가 포함된 경우 10진 구분 기호 문자는 CurrencyDecimalSeparator 속성으로 결정됩니다. 그렇지 않으면 소수 구분 문자가 NumberDecimalSeparator 속성으로 결정됩니다.

AllowExponent 128

숫자 문자열에 지수 표시가 있을 수 있음을 나타냅니다. AllowExponent 플래그를 사용하면 구문 분석된 문자열에 "E" 또는 "e" 문자로 시작하고 선택적 양 또는 음의 부호 및 정수가 있는 지수를 포함할 수 있습니다. 즉, nnnExx, nnnE+xxnnnE-xx 형식으로 문자열을 성공적으로 구문 분석합니다. 소수 구분 기호나 유효 숫자 또는 가수의 부호를 허용하지 않습니다. 구문 분석될 문자열에서 이러한 요소를 허용하려면 AllowDecimalPointAllowLeadingSign 플래그를 사용하거나 이러한 개별 플래그가 포함된 복합 스타일을 사용합니다.

AllowHexSpecifier 512

숫자 문자열이 16진수 값을 나타낸다는 것을 나타냅니다. 유효한 16진수 값은 0부터 9까지의 숫자와 A부터 F 및 a부터 f까지의 16진 문자를 포함합니다. 이 스타일을 사용하여 구문 분석되는 문자열은 접두사로 "0x" 또는 "&h"로 지정할 수 없습니다. AllowHexSpecifier 스타일을 사용하여 구문 분석된 문자열은 항상 16진수 값으로 해석됩니다. AllowHexSpecifier와 함께 사용할 수 있는 플래그는 AllowLeadingWhiteAllowTrailingWhite뿐입니다. NumberStyles 열거형에는 이러한 세 플래그로 구성된 복합 스타일인 HexNumber가 포함됩니다.

AllowLeadingSign 4

숫자 문자열에 선행 부호가 있을 수 있음을 나타냅니다. 유효한 선행 부호 문자는 PositiveSignNegativeSign 속성으로 결정됩니다.

AllowLeadingWhite 1

구문 분석된 문자열에 선행 공백 문자를 사용할 수 있음을 나타냅니다. 공백 문자의 유니코드 값은 U+0009, U+000A, U+000B, U+000C, U+000D 및 U+0020입니다. 이는 IsWhiteSpace(Char) 메서드가 true를 반환하는 문자의 하위 집합입니다.

AllowParentheses 16

숫자 문자열에 숫자를 둘러싸는 한 쌍의 괄호가 있을 수 있음을 나타냅니다. 괄호는 구문 분석될 문자열이 음수를 나타냄을 나타냅니다.

AllowThousands 64

숫자 문자열에 1000 단위를 구분하는 기호와 같은 그룹 구분 기호가 있을 수 있음을 나타냅니다. 값에 NumberStyles 플래그가 AllowCurrencySymbol 포함되고 구문 분석할 문자열에 통화 기호가 포함된 경우 유효한 그룹 구분 기호 문자는 속성에 의해 CurrencyGroupSeparator 결정되고 각 그룹의 숫자 수는 속성에 의해 CurrencyGroupSizes 결정됩니다. 그렇지 않으면 유효한 그룹 구분 문자가 NumberGroupSeparator 속성으로 결정되며 각 그룹의 자릿수는 NumberGroupSizes 속성으로 결정됩니다.

AllowTrailingSign 8

숫자 문자열에 후행 부호가 있을 수 있음을 나타냅니다. 유효한 후행 부호 문자는 PositiveSignNegativeSign 속성으로 결정됩니다.

AllowTrailingWhite 2

구문 분석된 문자열에 후행 공백 문자를 사용할 수 있음을 나타냅니다. 공백 문자의 유니코드 값은 U+0009, U+000A, U+000B, U+000C, U+000D 및 U+0020입니다. 이는 IsWhiteSpace(Char) 메서드가 true를 반환하는 문자의 하위 집합입니다.

Any 511

AllowHexSpecifier를 제외한 모든 스타일을 사용함을 나타냅니다. 이것은 복합 숫자 스타일입니다.

BinaryNumber 1027

AllowLeadingWhite, AllowTrailingWhiteAllowBinarySpecifier 스타일을 사용함을 나타냅니다. 이것은 복합 숫자 스타일입니다.

Currency 383

AllowExponentAllowHexSpecifier를 제외한 모든 스타일을 사용함을 나타냅니다. 이것은 복합 숫자 스타일입니다.

Float 167

AllowLeadingWhite, AllowTrailingWhite, AllowLeadingSign, AllowDecimalPointAllowExponent 스타일을 사용함을 나타냅니다. 이것은 복합 숫자 스타일입니다.

HexNumber 515

AllowLeadingWhite, AllowTrailingWhiteAllowHexSpecifier 스타일을 사용함을 나타냅니다. 이것은 복합 숫자 스타일입니다.

Integer 7

AllowLeadingWhite, AllowTrailingWhiteAllowLeadingSign 스타일을 사용함을 나타냅니다. 이것은 복합 숫자 스타일입니다.

None 0

구문 분석된 문자열에 선행 또는 후행 공백, 1000단위 구분 기호, 소수 구분 기호와 같은 스타일 요소가 있을 수 없다는 것을 나타냅니다. 구문 분석될 문자열은 정수로만 구성되어야 합니다.

Number 111

AllowLeadingWhite, AllowTrailingWhite, AllowLeadingSign, AllowTrailingSign, AllowDecimalPointAllowThousands 스타일을 사용함을 나타냅니다. 이것은 복합 숫자 스타일입니다.

예제

이 예제에서는 다양한 NumberStyles 플래그를 사용하여 문자열을 32비트 정수로 구문 분석하는 방법을 보여 줍니다.

using namespace System;
using namespace System::Text;
using namespace System::Globalization;


int main()
{
    // Parse the string as a hex value and display the
    // value as a decimal.
    String^ numberString = "A";
    int stringValue = Int32::Parse(numberString, NumberStyles::HexNumber);
    Console::WriteLine("{0} in hex = {1} in decimal.",
        numberString, stringValue);

    // Parse the string, allowing a leading sign, and ignoring
    // leading and trailing white spaces.
    numberString = "    -45   ";
    stringValue =Int32::Parse(numberString, NumberStyles::AllowLeadingSign |
        NumberStyles::AllowLeadingWhite | NumberStyles::AllowTrailingWhite);
    Console::WriteLine("'{0}' parsed to an int is '{1}'.",
        numberString, stringValue);

    // Parse the string, allowing parentheses, and ignoring
    // leading and trailing white spaces.
    numberString = "    (37)   ";
    stringValue = Int32::Parse(numberString, NumberStyles::AllowParentheses |
        NumberStyles::AllowLeadingSign | NumberStyles::AllowLeadingWhite |
        NumberStyles::AllowTrailingWhite);

    Console::WriteLine("'{0}' parsed to an int is '{1}'.",
        numberString, stringValue);
}

// This code produces the following output.
//
// A in hex = 10 in decimal.
// '    -45   ' parsed to an int is '-45'.
// '    (37)   ' parsed to an int is '-37'.
using System;
using System.Text;
using System.Globalization;

public sealed class App
{
    static void Main()
    {
        // Parse the string as a hex value and display the value as a decimal.
        String num = "A";
        int val = int.Parse(num, NumberStyles.HexNumber);
        Console.WriteLine("{0} in hex = {1} in decimal.", num, val);

        // Parse the string, allowing a leading sign, and ignoring leading and trailing white spaces.
        num = "    -45   ";
        val = int.Parse(num, NumberStyles.AllowLeadingSign |
            NumberStyles.AllowLeadingWhite | NumberStyles.AllowTrailingWhite);
        Console.WriteLine("'{0}' parsed to an int is '{1}'.", num, val);

        // Parse the string, allowing parentheses, and ignoring leading and trailing white spaces.
        num = "    (37)   ";
        val = int.Parse(num, NumberStyles.AllowParentheses | NumberStyles.AllowLeadingSign |                         NumberStyles.AllowLeadingWhite | NumberStyles.AllowTrailingWhite);
        Console.WriteLine("'{0}' parsed to an int is '{1}'.", num, val);
    }
}

// This code produces the following output.
//
// A in hex = 10 in decimal.
// '    -45   ' parsed to an int is '-45'.
// '    (37)   ' parsed to an int is '-37'.
Imports System.Globalization
Imports System.Text

Public Module Example
   Public Sub Main() 
      ' Parse the string as a hex value and display the value as a decimal.
      Dim num As String = "A"
      Dim val As Integer = Int32.Parse(num, NumberStyles.HexNumber)
      Console.WriteLine("{0} in hex = {1} in decimal.", num, val)

      ' Parse the string, allowing a leading sign, and ignoring leading and trailing white spaces.
      num = "    -45   "
      val = Integer.Parse(num, NumberStyles.AllowLeadingSign Or 
                               NumberStyles.AllowLeadingWhite Or 
                               NumberStyles.AllowTrailingWhite)
      Console.WriteLine("'{0}' parsed to an integer is '{1}'.", num, val)

      ' Parse the string, allowing parentheses, and ignoring leading and trailing white spaces.
      num = "    (37)   "
      val = Integer.Parse(num, NumberStyles.AllowParentheses Or 
                               NumberStyles.AllowLeadingSign Or
                               NumberStyles.AllowLeadingWhite Or 
                               NumberStyles.AllowTrailingWhite)
      Console.WriteLine("'{0}' parsed to an integer is '{1}'.", num, val)
   End Sub
End Module
' The example displays the following output:
'       A in hex = 10 in decimal.
'       '    -45   ' parsed to an int is '-45'.
'       '    (37)   ' parsed to an int is '-37'.

설명

열거형은 NumberStyles 숫자 값의 문자열 표현을 구문 분석하는 데 사용되는 두 종류의 열거형 값으로 구성됩니다.

  • 구문 분석된 문자열에 있을 수 있는 특정 스타일 요소(예: 공백 및 그룹 구분 기호)를 정의하는 개별 필드 플래그입니다.

  • 복합 숫자 스타일 - 구문 분석된 문자열에 있을 수 있는 스타일 요소를 정의하는 여러 필드 플래그로 구성됩니다.

AllowHexSpecifier제외하고 열거형의 개별 필드 플래그 NumberStyles 는 10진수의 문자열 표현을 구문 분석할 때 사용되는 스타일 요소를 정의합니다. None 는 구문 분석된 문자열에 숫자만 있을 수 있음을 나타냅니다. 나머지 개별 필드 플래그는 구문 분석 작업이 성공하기 위해 10진수의 문자열 표현에 있을 수 있지만 그렇게 할 필요는 없는 스타일 요소를 정의합니다. 반면, 플래그는 AllowHexSpecifier 구문 분석할 문자열이 항상 16진수 값으로 해석됨을 나타냅니다. 와 함께 AllowHexSpecifier 사용할 수 있는 유일한 개별 필드 플래그는 및 AllowTrailingWhite입니다AllowLeadingWhite. 열거형에는 NumberStyles 세 플래그 모두로 구성된 복합 숫자 스타일 HexNumber가 포함됩니다.

구문 분석할 문자열에 나타날 수 있는 기호(예: 통화 기호, 그룹 구분 기호, 소수 구분 기호 및 양수 및 음수 기호)는 메서드에 암시적으로 또는 명시적으로 전달되는 개체의 System.Globalization.NumberFormatInfo 멤버에 Parse 의해 정의됩니다. 이 항목의 멤버 테이블은 각 개별 플래그에 대한 설명을 제공하고 속성과의 관계를 NumberFormatInfo 나타냅니다.

다음 표에서는 복합 숫자 스타일을 나열하고 포함된 개별 필드 플래그를 나타냅니다. 셀의 "1"은 복합 숫자 스타일에 해당 행의 개별 숫자 스타일이 포함되어 있음을 나타냅니다. "0"은 복합 숫자 스타일에 개별 숫자 스타일이 포함되지 않음을 나타냅니다.

모두 통화 Float 정수 Number HexNumber
AllowHexSpecifier(0x0200) 0 0 0 0 0 1
AllowCurrencySymbol(0x0100) 1 1 0 0 0 0
AllowExponent(0x0080) 1 0 1 0 0 0
AllowThousands(0x0040) 1 1 0 0 1 0
AllowDecimalPoint(0x0020) 1 1 1 0 1 0
AllowParentheses(0x0010) 1 1 0 0 0 0
AllowTrailingSign(0x0008) 1 1 0 0 1 0
AllowLeadingSign(0x0004) 1 1 1 1 1 0
AllowTrailingWhite(0x0002) 1 1 1 1 1 1
AllowLeadingWhite(0x0001) 1 1 1 1 1 1
(0x1ff) (0x17f) (0x0a7) (0x007) (0x06f) (0x203)

적용 대상

추가 정보