UInt32.Parse メソッド

定義

数値の文字列形式を、それと等価な 32 ビット符号なし整数に変換します。

オーバーロード

Parse(String, NumberStyles, IFormatProvider)

指定したスタイルおよびカルチャ固有の書式にある数値の文字列表記を、それと等価な 32 ビット符号なし整数に変換します。

Parse(ReadOnlySpan<Char>, NumberStyles, IFormatProvider)

指定したスタイルおよびカルチャ固有の書式による数値のスパン表現を、等価の 32 ビット符号なし整数に変換します。

Parse(ReadOnlySpan<Byte>, NumberStyles, IFormatProvider)

UTF-8 文字のスパンを値に解析します。

Parse(String, IFormatProvider)

指定したカルチャ固有の書式による数値の文字列形式を、それと等価な 32 ビット符号なし整数に変換します。

Parse(String, NumberStyles)

指定したスタイルの数値の文字列形式を、それと等価な 32 ビット符号なし整数に変換します。

Parse(ReadOnlySpan<Char>, IFormatProvider)

文字のスパンを値に解析します。

Parse(ReadOnlySpan<Byte>, IFormatProvider)

UTF-8 文字のスパンを値に解析します。

Parse(String)

数値の文字列形式を、それと等価な 32 ビット符号なし整数に変換します。

Parse(String, NumberStyles, IFormatProvider)

重要

この API は CLS 準拠ではありません。

CLS 準拠の代替
System.Int64.Parse(String)

指定したスタイルおよびカルチャ固有の書式にある数値の文字列表記を、それと等価な 32 ビット符号なし整数に変換します。

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

パラメーター

s
String

変換する数値を表す文字列。 文字列は、style パラメーターで指定されたスタイルを使用して解釈されます。

style
NumberStyles

s で存在する可能性を持つスタイル要素を示す、列挙値のビットごとの組み合わせ。 通常指定する値は、Integer です。

provider
IFormatProvider

s に関するカルチャ固有の書式情報を提供するオブジェクト。

戻り値

s で指定した数値と等しい 32 ビット符号なし整数。

実装

属性

例外

snullです。

styleNumberStyles 値ではありません。

- または -

styleAllowHexSpecifier 値と HexNumber 値の組み合わせではありません。

s の形式が style に準拠していません。

s は、 UInt32.MinValue より小さいか、 UInt32.MaxValue より大きい数値を表します。

- または -

s に 0 以外の小数部の桁が含まれています。

次の例では、 メソッドを Parse(String, NumberStyles, IFormatProvider) 使用して、数値のさまざまな文字列形式を 32 ビット符号なし整数値に変換します。

using System;
using System.Globalization;

public class Example
{
   public static void Main()
   {
      string[] cultureNames= { "en-US", "fr-FR" };
      NumberStyles[] styles= { NumberStyles.Integer,
                               NumberStyles.Integer | NumberStyles.AllowDecimalPoint };
      string[] values = { "170209", "+170209.0", "+170209,0", "-103214.00",
                                 "-103214,00", "104561.1", "104561,1" };
      
      // Parse strings using each culture
      foreach (string cultureName in cultureNames)
      {
         CultureInfo ci = new CultureInfo(cultureName);
         Console.WriteLine("Parsing strings using the {0} culture", 
                           ci.DisplayName);
         // Use each style.
         foreach (NumberStyles style in styles)
         {
            Console.WriteLine("   Style: {0}", style.ToString());
            // Parse each numeric string.
            foreach (string value in values)
            {
               try {
                  Console.WriteLine("      Converted '{0}' to {1}.", value,
                                    UInt32.Parse(value, style, ci));
               }
               catch (FormatException) {
                  Console.WriteLine("      Unable to parse '{0}'.", value);
               }      
               catch (OverflowException) {
                  Console.WriteLine("      '{0}' is out of range of the UInt32 type.",
                                    value);
               }
            }
         }
      }                                    
   }
}
// The example displays the following output:
//       Parsing strings using the English (United States) culture
//          Style: Integer
//             Converted '170209' to 170209.
//             Unable to parse '+170209.0'.
//             Unable to parse '+170209,0'.
//             Unable to parse '-103214.00'.
//             Unable to parse '-103214,00'.
//             Unable to parse '104561.1'.
//             Unable to parse '104561,1'.
//          Style: Integer, AllowDecimalPoint
//             Converted '170209' to 170209.
//             Converted '+170209.0' to 170209.
//             Unable to parse '+170209,0'.
//             '-103214.00' is out of range of the UInt32 type.
//             Unable to parse '-103214,00'.
//             '104561.1' is out of range of the UInt32 type.
//             Unable to parse '104561,1'.
//       Parsing strings using the French (France) culture
//          Style: Integer
//             Converted '170209' to 170209.
//             Unable to parse '+170209.0'.
//             Unable to parse '+170209,0'.
//             Unable to parse '-103214.00'.
//             Unable to parse '-103214,00'.
//             Unable to parse '104561.1'.
//             Unable to parse '104561,1'.
//          Style: Integer, AllowDecimalPoint
//             Converted '170209' to 170209.
//             Unable to parse '+170209.0'.
//             Converted '+170209,0' to 170209.
//             Unable to parse '-103214.00'.
//             '-103214,00' is out of range of the UInt32 type.
//             Unable to parse '104561.1'.
//             '104561,1' is out of range of the UInt32 type.
open System
open System.Globalization

let cultureNames = [| "en-US"; "fr-FR" |]
let styles = 
    [| NumberStyles.Integer; NumberStyles.Integer ||| NumberStyles.AllowDecimalPoint |]
let values = 
    [| "170209"; "+170209.0"; "+170209,0"; "-103214.00"; "-103214,00"; "104561.1"; "104561,1" |]

// Parse strings using each culture
for cultureName in cultureNames do
    let ci = CultureInfo cultureName
    printfn $"Parsing strings using the {ci.DisplayName} culture"
    // Use each style.
    for style in styles do
        printfn $"   Style: {style}"
        // Parse each numeric string.
        for value in values do
            try
                printfn $"      Converted '{value}' to {UInt32.Parse(value, style, ci)}."
            with
            | :? FormatException ->
                printfn $"      Unable to parse '{value}'."
            | :? OverflowException ->
                printfn $"      '{value}' is out of range of the UInt32 type."
// The example displays the following output:
//       Parsing strings using the English (United States) culture
//          Style: Integer
//             Converted '170209' to 170209.
//             Unable to parse '+170209.0'.
//             Unable to parse '+170209,0'.
//             Unable to parse '-103214.00'.
//             Unable to parse '-103214,00'.
//             Unable to parse '104561.1'.
//             Unable to parse '104561,1'.
//          Style: Integer, AllowDecimalPoint
//             Converted '170209' to 170209.
//             Converted '+170209.0' to 170209.
//             Unable to parse '+170209,0'.
//             '-103214.00' is out of range of the UInt32 type.
//             Unable to parse '-103214,00'.
//             '104561.1' is out of range of the UInt32 type.
//             Unable to parse '104561,1'.
//       Parsing strings using the French (France) culture
//          Style: Integer
//             Converted '170209' to 170209.
//             Unable to parse '+170209.0'.
//             Unable to parse '+170209,0'.
//             Unable to parse '-103214.00'.
//             Unable to parse '-103214,00'.
//             Unable to parse '104561.1'.
//             Unable to parse '104561,1'.
//          Style: Integer, AllowDecimalPoint
//             Converted '170209' to 170209.
//             Unable to parse '+170209.0'.
//             Converted '+170209,0' to 170209.
//             Unable to parse '-103214.00'.
//             '-103214,00' is out of range of the UInt32 type.
//             Unable to parse '104561.1'.
//             '104561,1' is out of range of the UInt32 type.
Imports System.Globalization

Module Example
   Public Sub Main()
      Dim cultureNames() As String = { "en-US", "fr-FR" }
      Dim styles() As NumberStyles = { NumberStyles.Integer, _
                                       NumberStyles.Integer Or NumberStyles.AllowDecimalPoint }
      Dim values() As String = { "170209", "+170209.0", "+170209,0", "-103214.00", _
                                 "-103214,00", "104561.1", "104561,1" }
      
      ' Parse strings using each culture
      For Each cultureName As String In cultureNames
         Dim ci As New CultureInfo(cultureName)
         Console.WriteLine("Parsing strings using the {0} culture", ci.DisplayName)
         ' Use each style.
         For Each style As NumberStyles In styles
            Console.WriteLine("   Style: {0}", style.ToString())
            ' Parse each numeric string.
            For Each value As String In values
               Try
                  Console.WriteLine("      Converted '{0}' to {1}.", value, _
                                    UInt32.Parse(value, style, ci))
               Catch e As FormatException
                  Console.WriteLine("      Unable to parse '{0}'.", value)   
               Catch e As OverflowException
                  Console.WriteLine("      '{0}' is out of range of the UInt32 type.", _
                                    value)         
               End Try
            Next
         Next
      Next                                    
   End Sub
End Module
' The example displays the following output:
'       Parsing strings using the English (United States) culture
'          Style: Integer
'             Converted '170209' to 170209.
'             Unable to parse '+170209.0'.
'             Unable to parse '+170209,0'.
'             Unable to parse '-103214.00'.
'             Unable to parse '-103214,00'.
'             Unable to parse '104561.1'.
'             Unable to parse '104561,1'.
'          Style: Integer, AllowDecimalPoint
'             Converted '170209' to 170209.
'             Converted '+170209.0' to 170209.
'             Unable to parse '+170209,0'.
'             '-103214.00' is out of range of the UInt32 type.
'             Unable to parse '-103214,00'.
'             '104561.1' is out of range of the UInt32 type.
'             Unable to parse '104561,1'.
'       Parsing strings using the French (France) culture
'          Style: Integer
'             Converted '170209' to 170209.
'             Unable to parse '+170209.0'.
'             Unable to parse '+170209,0'.
'             Unable to parse '-103214.00'.
'             Unable to parse '-103214,00'.
'             Unable to parse '104561.1'.
'             Unable to parse '104561,1'.
'          Style: Integer, AllowDecimalPoint
'             Converted '170209' to 170209.
'             Unable to parse '+170209.0'.
'             Converted '+170209,0' to 170209.
'             Unable to parse '-103214.00'.
'             '-103214,00' is out of range of the UInt32 type.
'             Unable to parse '104561.1'.
'             '104561,1' is out of range of the UInt32 type.

注釈

パラメーターは style 、解析操作を成功させるために パラメーターで s 許可されるスタイル要素 (空白や正または負の符号記号など) を定義します。 列挙体のビット フラグ NumberStyles の組み合わせである必要があります。

style値に応じて、 パラメーターに s 次の要素を含めることができます。

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

角かっこ ([ および ]) 内の要素は省略可能です。 に が含まれているNumberStyles.AllowHexSpecifier場合style、パラメーターにはs次の要素を含めることができます。

[ws]hexdigits[ws]

次の表は、それぞれの要素の説明です。

要素 説明
ws オプションの空白。 空白は、 フラグを含む場合は のs先頭に表示され、フラグが含NumberStyles.AllowLeadingWhiteまれている場合styleは のs末尾にNumberStyles.AllowTrailingWhite表示styleされます。
$ カルチャ固有の通貨記号。 文字列内での位置は、 パラメーターの メソッドによってCurrencyPositivePattern返される オブジェクトの provider プロパティによってGetFormat定義NumberFormatInfoされます。 に フラグが含まれている場合styleは、通貨記号を にsNumberStyles.AllowCurrencySymbol表示できます。
sign 省略可能な記号。 (メソッドは、 OverflowException に負の符号を含め、0 以外の数値を表す 場合sに をスローします。署名は、 が フラグを含むNumberStyles.AllowLeadingSign場合styleは のs先頭に表示され、フラグが含まれている場合styleは のs末尾にNumberStyles.AllowTrailingSign表示されます。 に フラグが含まれている場合styleは、かっこを使用sして負の値をNumberStyles.AllowParentheses示すことができます。
数値 0 から 9 までの数字のシーケンス。
. カルチャ固有の小数点記号。 に フラグが含まれている場合styleは、現在のカルチャの小数点記号を NumberStyles.AllowDecimalPoints表示できます。
fractional_digits フラグを含むNumberStyles.AllowExponent場合styleは数字 0 から 9 の 1 つ以上の出現、そうでない場合は数字 0 の 1 つ以上の出現。 小数部の数字は、 に s フラグがNumberStyles.AllowDecimalPoint含まれている場合styleにのみ表示されます。
E "e" または "E" 文字。値が指数 (指数) 表記で表されることを示します。 フラグが含まれている場合style、パラメーターはs指数表記で数値をNumberStyles.AllowExponent表すことができます。
exponential_digits 0 から 9 までの数字のシーケンス。 フラグが含まれている場合style、パラメーターはs指数表記で数値を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 要素。 ただし、style に フラグが含 NumberStyles.AllowExponent まれていない場合、 fractional_digits は 1 桁以上の 0 桁のみで構成する必要があります。それ以外の場合は、 OverflowException がスローされます。
NumberStyles.AllowExponent 指数表記と exponential_digitsを示す "e" または "E" 文字。
NumberStyles.AllowLeadingWhite の先頭sにある ws 要素。
NumberStyles.AllowTrailingWhite の末尾sにある ws 要素。
NumberStyles.AllowLeadingSign 数字の前の記号。
NumberStyles.AllowTrailingSign 数字の後の記号。
NumberStyles.AllowParentheses 負の値を示す 数字 の前と後のかっこ。
NumberStyles.AllowThousands グループ区切り記号 (,) 要素。
NumberStyles.AllowCurrencySymbol currency ($) 要素。

フラグを使用する NumberStyles.AllowHexSpecifier 場合は、 s 16 進値にする必要があります。 と組み合わせることができる他のフラグは NumberStyles.AllowLeadingWhiteNumberStyles.AllowTrailingWhiteのみです。 (列挙には NumberStylesNumberStyles.HexNumber両方の空白フラグを含む複合数値スタイル が含まれています)。

Note

パラメーターが s 16 進数の文字列表現である場合、その前に 16 進数として区別する装飾 (や &hなど0x) を付けることはできません。 これにより、解析操作で例外がスローされます。

パラメーターはproviderIFormatProviderGetFormat形式sに関するカルチャ固有の情報をNumberFormatInfo提供する オブジェクトをメソッドが返す実装です。 パラメーターを使用 provider して、解析操作にカスタム書式情報を指定するには、次の 3 つの方法があります。

  • 書式設定情報を提供する実際 NumberFormatInfo の オブジェクトを渡すことができます。 (の実装 GetFormat は、単にそれ自体を返します)。

  • 書式設定を CultureInfo 使用するカルチャを指定する オブジェクトを渡すことができます。 その NumberFormat プロパティは、書式設定情報を提供します。

  • カスタム IFormatProvider 実装を渡すことができます。 そのメソッドは GetFormat 、書式設定情報を提供する オブジェクトを NumberFormatInfo インスタンス化して返す必要があります。

nullの場合providerは、現在のNumberFormatInfoカルチャの オブジェクトが使用されます。

こちらもご覧ください

適用対象

Parse(ReadOnlySpan<Char>, NumberStyles, IFormatProvider)

重要

この API は CLS 準拠ではありません。

指定したスタイルおよびカルチャ固有の書式による数値のスパン表現を、等価の 32 ビット符号なし整数に変換します。

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

パラメーター

s
ReadOnlySpan<Char>

変換する数値を表す文字を格納しているスパン。 スパンは、style パラメーターで指定されたスタイルを使用して解釈されます。

style
NumberStyles

s で存在する可能性を持つスタイル要素を示す、列挙値のビットごとの組み合わせ。 通常指定する値は、Integer です。

provider
IFormatProvider

s に関するカルチャ固有の書式情報を提供するオブジェクト。

戻り値

s で指定した数値と等しい 32 ビット符号なし整数。

実装

属性

適用対象

Parse(ReadOnlySpan<Byte>, NumberStyles, IFormatProvider)

UTF-8 文字のスパンを値に解析します。

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

パラメーター

utf8Text
ReadOnlySpan<Byte>

解析する UTF-8 文字のスパン。

style
NumberStyles

utf8Text存在できる数値スタイルのビットごとの組み合わせ。

provider
IFormatProvider

utf8Text に関するカルチャ固有の書式情報を提供するオブジェクト。

戻り値

を解析した utf8Text結果。

実装

適用対象

Parse(String, IFormatProvider)

重要

この API は CLS 準拠ではありません。

CLS 準拠の代替
System.Int64.Parse(String)

指定したカルチャ固有の書式による数値の文字列形式を、それと等価な 32 ビット符号なし整数に変換します。

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

パラメーター

s
String

変換する数値を表す文字列。

provider
IFormatProvider

s に関するカルチャ固有の書式情報を提供するオブジェクト。

戻り値

s で指定した数値と等しい 32 ビット符号なし整数。

実装

属性

例外

snullです。

s が正しい形式ではありません。

s は、 UInt32.MinValue より小さいか、 UInt32.MaxValue より大きい数値を表します。

次の例は、Web フォームのボタン クリック イベント ハンドラーです。 プロパティによって返される配列を HttpRequest.UserLanguages 使用して、ユーザーのロケールを決定します。 その後、そのロケールに CultureInfo 対応する オブジェクトをインスタンス化します。 NumberFormatInfoそのCultureInfoオブジェクトに属する オブジェクトが メソッドにParse(String, IFormatProvider)渡され、ユーザーの入力が値にUInt32変換されます。

protected void OkToUInteger_Click(object sender, EventArgs e)
{
    string locale;
    uint number;
    CultureInfo culture;

    // Return if string is empty
    if (String.IsNullOrEmpty(this.inputNumber.Text))
        return;

    // Get locale of web request to determine possible format of number
    if (Request.UserLanguages.Length == 0)
        return;
    locale = Request.UserLanguages[0];
    if (String.IsNullOrEmpty(locale))
        return;

    // Instantiate CultureInfo object for the user's locale
    culture = new CultureInfo(locale);

    // Convert user input from a string to a number
    try
    {
        number = UInt32.Parse(this.inputNumber.Text, culture.NumberFormat);
    }
    catch (FormatException)
    {
        return;
    }
    catch (Exception)
    {
        return;
    }
    // Output number to label on web form
    this.outputNumber.Text = "Number is " + number.ToString();
}
Protected Sub OKToUInteger_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles OKToUInteger.Click
   Dim locale As String
   Dim culture As CultureInfo
   Dim number As UInteger

   ' Return if string is empty
   If String.IsNullOrEmpty(Me.inputNumber.Text) Then Exit Sub

   ' Get locale of web request to determine possible format of number
   If Request.UserLanguages.Length = 0 Then Exit Sub
   locale = Request.UserLanguages(0)
   If String.IsNullOrEmpty(locale) Then Exit Sub

   ' Instantiate CultureInfo object for the user's locale
   culture = New CultureInfo(locale)

   ' Convert user input from a string to a number
   Try
      number = UInt32.Parse(Me.inputNumber.Text, culture.NumberFormat)
   Catch ex As FormatException
      Exit Sub
   Catch ex As Exception
      Exit Sub
   End Try

   ' Output number to label on web form
   Me.outputNumber.Text = "Number is " & number.ToString()
End Sub

注釈

パラメーターには s 、次の形式の数値が含まれています。

[ws][sign]digits[ws]

角かっこ ([ と ]) の項目は省略可能です。 次の表は、それぞれの要素の説明です。

要素 説明
ws オプションの空白。
sign 省略可能な符号、または負の符号 (値が 0 を表す場合 s )。
数値 0 から 9 までの数字のシーケンス。

s パラメーターは、 スタイルを NumberStyles.Integer 使用して解釈されます。 符号なし整数値の 10 進数に加えて、先頭と末尾のスペースと先頭の符号のみを使用できます。 (負の符号が存在する場合は、 s 0 の値を表す必要があります。または、 メソッドによって が OverflowExceptionスローされます)。に存在できるカルチャ固有の書式設定情報と共にスタイル要素を明示的に s定義するには、 メソッドを Parse(String, NumberStyles, IFormatProvider) 使用します。

パラメーターはproviderIFormatProviderGetFormat形式sに関するカルチャ固有の情報をNumberFormatInfo提供する オブジェクトをメソッドが返す実装です。 パラメーターを使用 provider して、解析操作にカスタム書式情報を指定するには、次の 3 つの方法があります。

  • 書式設定情報を提供する実際 NumberFormatInfo の オブジェクトを渡すことができます。 (の実装 GetFormat は、単にそれ自体を返します)。

  • 書式設定を CultureInfo 使用するカルチャを指定する オブジェクトを渡すことができます。 その NumberFormat プロパティは、書式設定情報を提供します。

  • カスタム IFormatProvider 実装を渡すことができます。 そのメソッドは GetFormat 、書式設定情報を提供する オブジェクトを NumberFormatInfo インスタンス化して返す必要があります。

が のnull場合providerは、NumberFormatInfo現在のカルチャの が使用されます。

こちらもご覧ください

適用対象

Parse(String, NumberStyles)

重要

この API は CLS 準拠ではありません。

CLS 準拠の代替
System.Int64.Parse(String)

指定したスタイルの数値の文字列形式を、それと等価な 32 ビット符号なし整数に変換します。

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

パラメーター

s
String

変換する数値を表す文字列。 文字列は、style パラメーターで指定されたスタイルを使用して解釈されます。

style
NumberStyles

s に許可されている書式を指定する列挙値のビットごとの組み合わせ。 通常指定する値は、Integer です。

戻り値

s で指定した数値と等しい 32 ビット符号なし整数。

属性

例外

snullです。

styleNumberStyles 値ではありません。

- または -

styleAllowHexSpecifier 値と HexNumber 値の組み合わせではありません。

s の形式が style に準拠していません。

s は、 UInt32.MinValue より小さいか、 UInt32.MaxValue より大きい数値を表します。

- または -

s に 0 以外の小数部の桁が含まれています。

次の例では、複数の値を使用して、文字列配列内の各要素の NumberStyles 解析を試みます。

using System;
using System.Globalization;

public class Example
{
   public static void Main()
   {
      string[] values= { " 214309 ", "1,064,181", "(0)", "10241+", " + 21499 ", 
                         " +21499 ", "122153.00", "1e03ff", "91300.0e-2" };
      NumberStyles whitespace =  NumberStyles.AllowLeadingWhite | NumberStyles.AllowTrailingWhite;
      NumberStyles[] styles= { NumberStyles.None, whitespace, 
                               NumberStyles.AllowLeadingSign | NumberStyles.AllowTrailingSign | whitespace, 
                               NumberStyles.AllowThousands | NumberStyles.AllowCurrencySymbol, 
                               NumberStyles.AllowExponent | NumberStyles.AllowDecimalPoint };

      // Attempt to convert each number using each style combination.
      foreach (string value in values)
      {
         Console.WriteLine("Attempting to convert '{0}':", value);
         foreach (NumberStyles style in styles)
         {
            try {
               uint number = UInt32.Parse(value, style);
               Console.WriteLine("   {0}: {1}", style, number);
            }   
            catch (FormatException) {
               Console.WriteLine("   {0}: Bad Format", style);
            }   
            catch (OverflowException)
            {
               Console.WriteLine("   {0}: Overflow", value);         
            }         
         }
         Console.WriteLine();
      }
   }
}
// The example displays the following output:
//    Attempting to convert ' 214309 ':
//       None: Bad Format
//       AllowLeadingWhite, AllowTrailingWhite: 214309
//       Integer, AllowTrailingSign: 214309
//       AllowThousands, AllowCurrencySymbol: Bad Format
//       AllowDecimalPoint, AllowExponent: Bad Format
//    
//    Attempting to convert '1,064,181':
//       None: Bad Format
//       AllowLeadingWhite, AllowTrailingWhite: Bad Format
//       Integer, AllowTrailingSign: Bad Format
//       AllowThousands, AllowCurrencySymbol: 1064181
//       AllowDecimalPoint, AllowExponent: Bad Format
//    
//    Attempting to convert '(0)':
//       None: Bad Format
//       AllowLeadingWhite, AllowTrailingWhite: Bad Format
//       Integer, AllowTrailingSign: Bad Format
//       AllowThousands, AllowCurrencySymbol: Bad Format
//       AllowDecimalPoint, AllowExponent: Bad Format
//    
//    Attempting to convert '10241+':
//       None: Bad Format
//       AllowLeadingWhite, AllowTrailingWhite: Bad Format
//       Integer, AllowTrailingSign: 10241
//       AllowThousands, AllowCurrencySymbol: Bad Format
//       AllowDecimalPoint, AllowExponent: Bad Format
//    
//    Attempting to convert ' + 21499 ':
//       None: Bad Format
//       AllowLeadingWhite, AllowTrailingWhite: Bad Format
//       Integer, AllowTrailingSign: Bad Format
//       AllowThousands, AllowCurrencySymbol: Bad Format
//       AllowDecimalPoint, AllowExponent: Bad Format
//    
//    Attempting to convert ' +21499 ':
//       None: Bad Format
//       AllowLeadingWhite, AllowTrailingWhite: Bad Format
//       Integer, AllowTrailingSign: 21499
//       AllowThousands, AllowCurrencySymbol: Bad Format
//       AllowDecimalPoint, AllowExponent: Bad Format
//    
//    Attempting to convert '122153.00':
//       None: Bad Format
//       AllowLeadingWhite, AllowTrailingWhite: Bad Format
//       Integer, AllowTrailingSign: Bad Format
//       AllowThousands, AllowCurrencySymbol: Bad Format
//       AllowDecimalPoint, AllowExponent: 122153
//    
//    Attempting to convert '1e03ff':
//       None: Bad Format
//       AllowLeadingWhite, AllowTrailingWhite: Bad Format
//       Integer, AllowTrailingSign: Bad Format
//       AllowThousands, AllowCurrencySymbol: Bad Format
//       AllowDecimalPoint, AllowExponent: Bad Format
//    
//    Attempting to convert '91300.0e-2':
//       None: Bad Format
//       AllowLeadingWhite, AllowTrailingWhite: Bad Format
//       Integer, AllowTrailingSign: Bad Format
//       AllowThousands, AllowCurrencySymbol: Bad Format
//       AllowDecimalPoint, AllowExponent: 913
open System
open System.Globalization

let values = 
    [| " 214309 "; "1,064,181"; "(0)"; "10241+"; " + 21499 " 
       " +21499 "; "122153.00"; "1e03ff"; "91300.0e-2" |]

let whitespace =  NumberStyles.AllowLeadingWhite ||| NumberStyles.AllowTrailingWhite
let styles = 
    [| NumberStyles.None; whitespace 
       NumberStyles.AllowLeadingSign ||| NumberStyles.AllowTrailingSign ||| whitespace
       NumberStyles.AllowThousands ||| NumberStyles.AllowCurrencySymbol
       NumberStyles.AllowExponent ||| NumberStyles.AllowDecimalPoint |]

// Attempt to convert each number using each style combination.
for value in values do
    printfn $"Attempting to convert '{value}':"
    for style in styles do
        try
            let number = UInt32.Parse(value, style)
            printfn $"   {style}: {number}"
        with
        | :? FormatException ->
            printfn $"   {style}: Bad Format"
        | :? OverflowException ->
            printfn $"   {value}: Overflow"
    printfn "" 
// The example displays the following output:
//    Attempting to convert ' 214309 ':
//       None: Bad Format
//       AllowLeadingWhite, AllowTrailingWhite: 214309
//       Integer, AllowTrailingSign: 214309
//       AllowThousands, AllowCurrencySymbol: Bad Format
//       AllowDecimalPoint, AllowExponent: Bad Format
//    
//    Attempting to convert '1,064,181':
//       None: Bad Format
//       AllowLeadingWhite, AllowTrailingWhite: Bad Format
//       Integer, AllowTrailingSign: Bad Format
//       AllowThousands, AllowCurrencySymbol: 1064181
//       AllowDecimalPoint, AllowExponent: Bad Format
//    
//    Attempting to convert '(0)':
//       None: Bad Format
//       AllowLeadingWhite, AllowTrailingWhite: Bad Format
//       Integer, AllowTrailingSign: Bad Format
//       AllowThousands, AllowCurrencySymbol: Bad Format
//       AllowDecimalPoint, AllowExponent: Bad Format
//    
//    Attempting to convert '10241+':
//       None: Bad Format
//       AllowLeadingWhite, AllowTrailingWhite: Bad Format
//       Integer, AllowTrailingSign: 10241
//       AllowThousands, AllowCurrencySymbol: Bad Format
//       AllowDecimalPoint, AllowExponent: Bad Format
//    
//    Attempting to convert ' + 21499 ':
//       None: Bad Format
//       AllowLeadingWhite, AllowTrailingWhite: Bad Format
//       Integer, AllowTrailingSign: Bad Format
//       AllowThousands, AllowCurrencySymbol: Bad Format
//       AllowDecimalPoint, AllowExponent: Bad Format
//    
//    Attempting to convert ' +21499 ':
//       None: Bad Format
//       AllowLeadingWhite, AllowTrailingWhite: Bad Format
//       Integer, AllowTrailingSign: 21499
//       AllowThousands, AllowCurrencySymbol: Bad Format
//       AllowDecimalPoint, AllowExponent: Bad Format
//    
//    Attempting to convert '122153.00':
//       None: Bad Format
//       AllowLeadingWhite, AllowTrailingWhite: Bad Format
//       Integer, AllowTrailingSign: Bad Format
//       AllowThousands, AllowCurrencySymbol: Bad Format
//       AllowDecimalPoint, AllowExponent: 122153
//    
//    Attempting to convert '1e03ff':
//       None: Bad Format
//       AllowLeadingWhite, AllowTrailingWhite: Bad Format
//       Integer, AllowTrailingSign: Bad Format
//       AllowThousands, AllowCurrencySymbol: Bad Format
//       AllowDecimalPoint, AllowExponent: Bad Format
//    
//    Attempting to convert '91300.0e-2':
//       None: Bad Format
//       AllowLeadingWhite, AllowTrailingWhite: Bad Format
//       Integer, AllowTrailingSign: Bad Format
//       AllowThousands, AllowCurrencySymbol: Bad Format
//       AllowDecimalPoint, AllowExponent: 913
Imports System.Globalization

Module Example
   Public Sub Main()
      Dim values() As String = { " 214309 ", "1,064,181", "(0)", "10241+", _
                                 " + 21499 ", " +21499 ", "122153.00", _
                                 "1e03ff", "91300.0e-2" }
      Dim whitespace As NumberStyles =  NumberStyles.AllowLeadingWhite Or NumberStyles.AllowTrailingWhite
      Dim styles() As NumberStyles = { NumberStyles.None, _
                                       whitespace, _
                                       NumberStyles.AllowLeadingSign Or NumberStyles.AllowTrailingSign Or whitespace, _
                                       NumberStyles.AllowThousands Or NumberStyles.AllowCurrencySymbol, _
                                       NumberStyles.AllowExponent Or NumberStyles.AllowDecimalPoint }

      ' Attempt to convert each number using each style combination.
      For Each value As String In values
         Console.WriteLine("Attempting to convert '{0}':", value)
         For Each style As NumberStyles In styles
            Try
               Dim number As UInteger = UInt32.Parse(value, style)
               Console.WriteLine("   {0}: {1}", style, number)
            Catch e As FormatException
               Console.WriteLine("   {0}: Bad Format", style)
            Catch e As OverflowException
               Console.WriteLine("   {0}: Overflow", value)         
            End Try         
         Next
         Console.WriteLine()
      Next
   End Sub
End Module
' The example displays the following output:
'    Attempting to convert ' 214309 ':
'       None: Bad Format
'       AllowLeadingWhite, AllowTrailingWhite: 214309
'       Integer, AllowTrailingSign: 214309
'       AllowThousands, AllowCurrencySymbol: Bad Format
'       AllowDecimalPoint, AllowExponent: Bad Format
'    
'    Attempting to convert '1,064,181':
'       None: Bad Format
'       AllowLeadingWhite, AllowTrailingWhite: Bad Format
'       Integer, AllowTrailingSign: Bad Format
'       AllowThousands, AllowCurrencySymbol: 1064181
'       AllowDecimalPoint, AllowExponent: Bad Format
'    
'    Attempting to convert '(0)':
'       None: Bad Format
'       AllowLeadingWhite, AllowTrailingWhite: Bad Format
'       Integer, AllowTrailingSign: Bad Format
'       AllowThousands, AllowCurrencySymbol: Bad Format
'       AllowDecimalPoint, AllowExponent: Bad Format
'    
'    Attempting to convert '10241+':
'       None: Bad Format
'       AllowLeadingWhite, AllowTrailingWhite: Bad Format
'       Integer, AllowTrailingSign: 10241
'       AllowThousands, AllowCurrencySymbol: Bad Format
'       AllowDecimalPoint, AllowExponent: Bad Format
'    
'    Attempting to convert ' + 21499 ':
'       None: Bad Format
'       AllowLeadingWhite, AllowTrailingWhite: Bad Format
'       Integer, AllowTrailingSign: Bad Format
'       AllowThousands, AllowCurrencySymbol: Bad Format
'       AllowDecimalPoint, AllowExponent: Bad Format
'    
'    Attempting to convert ' +21499 ':
'       None: Bad Format
'       AllowLeadingWhite, AllowTrailingWhite: Bad Format
'       Integer, AllowTrailingSign: 21499
'       AllowThousands, AllowCurrencySymbol: Bad Format
'       AllowDecimalPoint, AllowExponent: Bad Format
'    
'    Attempting to convert '122153.00':
'       None: Bad Format
'       AllowLeadingWhite, AllowTrailingWhite: Bad Format
'       Integer, AllowTrailingSign: Bad Format
'       AllowThousands, AllowCurrencySymbol: Bad Format
'       AllowDecimalPoint, AllowExponent: 122153
'    
'    Attempting to convert '1e03ff':
'       None: Bad Format
'       AllowLeadingWhite, AllowTrailingWhite: Bad Format
'       Integer, AllowTrailingSign: Bad Format
'       AllowThousands, AllowCurrencySymbol: Bad Format
'       AllowDecimalPoint, AllowExponent: Bad Format
'    
'    Attempting to convert '91300.0e-2':
'       None: Bad Format
'       AllowLeadingWhite, AllowTrailingWhite: Bad Format
'       Integer, AllowTrailingSign: Bad Format
'       AllowThousands, AllowCurrencySymbol: Bad Format
'       AllowDecimalPoint, AllowExponent: 913

注釈

パラメーターは style 、解析操作を成功させるためにパラメーターで s 許可されるスタイル要素 (空白、正または負の符号記号、グループ区切り記号、小数点記号など) を定義します。 style は、列挙型のビット フラグ NumberStyles の組み合わせである必要があります。 パラメーターはstyle、 で表される数値システム (10 進数または 16 進数) が実行時にのみ認識されるs場合、または で空白または記号をs禁止する場合に、16 進数の値の文字列表現を含む場合に、このメソッドオーバーロードを役立ちますs

style値に応じて、 パラメーターに s 次の要素を含めることができます。

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

角かっこ ([ および ]) 内の要素は省略可能です。 に が含まれているNumberStyles.AllowHexSpecifier場合style、パラメーターにはs次の要素を含めることができます。

[ws]hexdigits[ws]

次の表は、それぞれの要素の説明です。

要素 説明
ws オプションの空白。 空白は、 フラグを含む場合は のs先頭に表示され、フラグが含NumberStyles.AllowLeadingWhiteまれている場合styleは のs末尾にNumberStyles.AllowTrailingWhite表示styleされます。
$ カルチャ固有の通貨記号。 文字列内での位置は、現在のカルチャの NumberFormatInfo.CurrencyNegativePattern プロパティと NumberFormatInfo.CurrencyPositivePattern プロパティによって定義されます。 に フラグが含まれている場合styleは、現在のカルチャの通貨記号を NumberStyles.AllowCurrencySymbols表示できます。
sign 省略可能な記号。 署名は、 フラグが含まれている場合は のs先頭に表示され、フラグが含NumberStyles.AllowLeadingSignまれている場合styleは のs末尾にNumberStyles.AllowTrailingSign表示styleされます。 に フラグが含まれている場合styleは、かっこを使用sして負の値をNumberStyles.AllowParentheses示すことができます。 ただし、負符号記号は 0 でのみ使用できます。それ以外の場合、メソッドは を OverflowExceptionスローします。
数値

fractional_digits

exponential_digits
0 から 9 までの数字のシーケンス。 fractional_digitsの場合、数字 0 のみが有効です。
, カルチャ固有のグループ区切り記号。 に フラグが含まれている場合styleは、現在のカルチャのグループ区切り記号を NumberStyles.AllowThousandss表示できます。
. カルチャ固有の小数点記号。 に フラグが含まれている場合styleは、現在のカルチャの小数点記号を NumberStyles.AllowDecimalPoints表示できます。 解析操作を成功させるために小数部の数字として表示できるのは、数字 0 のみです。 fractional_digitsに他の 数字が含まれている場合は、 FormatException がスローされます。
E "e" または "E" 文字。値が指数 (指数) 表記で表されることを示します。 フラグが含まれている場合style、パラメーターはs指数表記で数値をNumberStyles.AllowExponent表すことができます。
hexdigits 0 から f、または 0 から F までの 16 進数のシーケンス。

注意

の終端 NUL (U+0000) 文字 s は、引数の style 値に関係なく、解析操作では無視されます。

数字のみを含む文字列 (スタイルに NumberStyles.None 対応) は、型の UInt32 範囲内にある場合は常に正常に解析されます。 残りの NumberStyles メンバーのほとんどは、入力文字列に存在する可能性がありますが、存在する必要がない要素を制御します。 次の表は、 にs存在する可能性がある要素に個々NumberStylesのメンバーがどのように影響するかを示しています。

NumberStyles 数字に加えて許可される s 要素
None digits 要素のみ。
AllowDecimalPoint 小数点 (.) と 小数部の要素
AllowExponent 指数表記と exponential_digitsを示す "e" または "E" 文字。
AllowLeadingWhite の先頭sにある ws 要素。
AllowTrailingWhite の末尾sにある ws 要素。
AllowLeadingSign の先頭sにある sign 要素。
AllowTrailingSign の末尾sにある sign 要素。
AllowParentheses 数値を囲むかっこの形式の 符号 要素。
AllowThousands グループ区切り記号 (,) 要素。
AllowCurrencySymbol currency ($) 要素。
Currency すべての要素。 ただし、 s 指数表記で 16 進数または数値を表すことはできません。
Float の先頭または末尾にある sws 要素、の先頭にs記号を付け、小数点 (.) 記号を指定します。 パラメーターでは s 指数表記を使用することもできます。
Number wssign、グループ区切り記号 ()、および小数点 (.) 要素。
Any すべての要素。 ただし、 s 16 進数を表すことはできません。

で特定のスタイル要素NumberStyles.AllowHexSpecifiersが存在することを可能にするが、必要としない他NumberStylesの値とは異なり、スタイル値は、 の個々の数値がs常に 16 進文字として解釈されることを意味します。 有効な 16 進文字は、0 から 9、A から F、および a から f です。 "0x" などのプレフィックスは使用できません。 パラメーターと組み合わせることができる他のフラグは NumberStyles.AllowLeadingWhitestyleNumberStyles.AllowTrailingWhiteのみです。 (列挙には NumberStylesNumberStyles.HexNumber両方の空白フラグを含む複合数値スタイル が含まれています)。

パラメーターと組み合わせることができる他のフラグは NumberStyles.AllowLeadingWhitestyleNumberStyles.AllowTrailingWhiteのみです。 (列挙には NumberStylesNumberStyles.HexNumber両方の空白フラグを含む複合数値スタイル が含まれています)。

Note

が 16 進数の文字列表現の場合s、前に 16 進数として区別する装飾 (や &hなど0x) を付けることはできません。 これにより、変換が失敗します。

パラメーターは s 、現在のシステム カルチャ用に初期化されたオブジェクトの NumberFormatInfo 書式設定情報を使用して解析されます。 解析操作に書式設定情報を使用するカルチャを指定するには、 オーバーロードを Parse(String, NumberStyles, IFormatProvider) 呼び出します。

こちらもご覧ください

適用対象

Parse(ReadOnlySpan<Char>, IFormatProvider)

文字のスパンを値に解析します。

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

パラメーター

s
ReadOnlySpan<Char>

解析する文字のスパン。

provider
IFormatProvider

s に関するカルチャ固有の書式情報を提供するオブジェクト。

戻り値

を解析した s結果。

実装

適用対象

Parse(ReadOnlySpan<Byte>, IFormatProvider)

UTF-8 文字のスパンを値に解析します。

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

パラメーター

utf8Text
ReadOnlySpan<Byte>

解析する UTF-8 文字のスパン。

provider
IFormatProvider

utf8Text に関するカルチャ固有の書式情報を提供するオブジェクト。

戻り値

を解析した utf8Text結果。

実装

適用対象

Parse(String)

重要

この API は CLS 準拠ではありません。

CLS 準拠の代替
System.Int64.Parse(String)

数値の文字列形式を、それと等価な 32 ビット符号なし整数に変換します。

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

パラメーター

s
String

変換する数値を表す文字列。

戻り値

s に格納されている数値と等しい 32 ビット符号なし整数。

属性

例外

s パラメーターが null です。

s パラメーターの形式が正しくありません。

パラメーターは sUInt32.MinValue より小さいか、UInt32.MaxValue より大きい数値 を表します

次の例では、 メソッドを Parse(String) 使用して文字列値の配列を解析します。

string[] values = { "+13230", "-0", "1,390,146", "$190,235,421,127",
                    "0xFA1B", "163042", "-10", "2147483648", 
                    "14065839182", "16e07", "134985.0", "-12034" };
foreach (string value in values)
{
   try {
      uint number = UInt32.Parse(value); 
      Console.WriteLine("{0} --> {1}", value, number);
   }
   catch (FormatException) {
      Console.WriteLine("{0}: Bad Format", value);
   }   
   catch (OverflowException) {
      Console.WriteLine("{0}: Overflow", value);   
   }  
}
// The example displays the following output:
//       +13230 --> 13230
//       -0 --> 0
//       1,390,146: Bad Format
//       $190,235,421,127: Bad Format
//       0xFA1B: Bad Format
//       163042 --> 163042
//       -10: Overflow
//       2147483648 --> 2147483648
//       14065839182: Overflow
//       16e07: Bad Format
//       134985.0: Bad Format
//       -12034: Overflow
open System

let values = 
    [| "+13230"; "-0"; "1,390,146"; "$190,235,421,127"
       "0xFA1B"; "163042"; "-10"; "2147483648"
       "14065839182"; "16e07"; "134985.0"; "-12034" |]

for value in values do
    try
        let number = UInt32.Parse value 
        printfn $"{value} --> {number}"
    with
    | :? FormatException ->
        printfn $"{value}: Bad Format"
    | :? OverflowException ->
        printfn $"{value}: Overflow"
// The example displays the following output:
//       +13230 --> 13230
//       -0 --> 0
//       1,390,146: Bad Format
//       $190,235,421,127: Bad Format
//       0xFA1B: Bad Format
//       163042 --> 163042
//       -10: Overflow
//       2147483648 --> 2147483648
//       14065839182: Overflow
//       16e07: Bad Format
//       134985.0: Bad Format
//       -12034: Overflow
Dim values() As String = { "+13230", "-0", "1,390,146", "$190,235,421,127", 
                           "0xFA1B", "163042", "-10", "2147483648",  
                           "14065839182", "16e07", "134985.0", "-12034" }
For Each value As String In values
   Try
      Dim number As UInteger = UInt32.Parse(value) 
      Console.WriteLine("{0} --> {1}", value, number)
   Catch e As FormatException
      Console.WriteLine("{0}: Bad Format", value)
   Catch e As OverflowException
      Console.WriteLine("{0}: Overflow", value)   
   End Try  
Next
' The example displays the following output:
'       +13230 --> 13230
'       -0 --> 0
'       1,390,146: Bad Format
'       $190,235,421,127: Bad Format
'       0xFA1B: Bad Format
'       163042 --> 163042
'       -10: Overflow
'       2147483648 --> 2147483648
'       14065839182: Overflow
'       16e07: Bad Format
'       134985.0: Bad Format
'       -12034: Overflow

注釈

パラメーターは s 、次の形式の数値の文字列表現である必要があります。

[ws][sign]digits[ws]

角かっこ ([ および ]) 内の要素は省略可能です。 次の表は、それぞれの要素の説明です。

要素 説明
ws オプションの空白。
sign 省略可能な記号。 有効な符号文字は、現在のカルチャの NumberFormatInfo.NegativeSign プロパティと NumberFormatInfo.PositiveSign プロパティによって決まります。 ただし、負符号記号は 0 でのみ使用できます。それ以外の場合、メソッドは を OverflowExceptionスローします。
数値 0 から 9 までの数字のシーケンス。 先行ゼロは無視されます。

注意

パラメーターで s 指定された文字列は、 スタイルを使用 NumberStyles.Integer して解釈されます。 グループ区切り記号または小数点記号を含めることはできません。また、小数部を含めることはできません。

パラメーターは s 、現在のシステム カルチャ用に初期化されたオブジェクトの System.Globalization.NumberFormatInfo 書式設定情報を使用して解析されます。 詳細については、「NumberFormatInfo.CurrentInfo」を参照してください。 特定のカルチャの書式設定情報を使用して文字列を解析するには、 メソッドを使用します Parse(String, IFormatProvider)

こちらもご覧ください

適用対象