UInt64.Parse メソッド

定義

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

オーバーロード

Parse(String, NumberStyles, IFormatProvider)

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

Parse(ReadOnlySpan<Char>, NumberStyles, IFormatProvider)

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

Parse(ReadOnlySpan<Byte>, NumberStyles, IFormatProvider)

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

Parse(String, IFormatProvider)

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

Parse(String, NumberStyles)

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

Parse(ReadOnlySpan<Char>, IFormatProvider)

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

Parse(ReadOnlySpan<Byte>, IFormatProvider)

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

Parse(String)

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

Parse(String, NumberStyles, IFormatProvider)

Source:
UInt64.cs
Source:
UInt64.cs
Source:
UInt64.cs

重要

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

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

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

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

パラメーター

s
String

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

style
NumberStyles

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

provider
IFormatProvider

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

戻り値

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

実装

属性

例外

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

styleNumberStyles 値ではありません。

- または -

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

s パラメーターの形式が style に準拠していません。

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

- または -

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

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

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,
                                    UInt64.Parse(value, style, ci));
               }
               catch (FormatException) {
                  Console.WriteLine("      Unable to parse '{0}'.", value);
               }      
               catch (OverflowException) {
                  Console.WriteLine("      '{0}' is out of range of the UInt64 type.",
                                    value);
               }
            }
         }
      }                                    
   }
}
// The example displays the following output:
//       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 UInt64 type.
//          Unable to parse '-103214,00'.
//          '104561.1' is out of range of the UInt64 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 UInt64 type.
//          Unable to parse '104561.1'.
//          '104561,1' is out of range of the UInt64 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 {UInt64.Parse(value, style, ci)}."
            with
            | :? FormatException ->
                printfn $"      Unable to parse '{value}'."
            | :? OverflowException ->
                printfn $"      '{value}' is out of range of the UInt64 type."
// The example displays the following output:
//       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 UInt64 type.
//          Unable to parse '-103214,00'.
//          '104561.1' is out of range of the UInt64 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 UInt64 type.
//          Unable to parse '104561.1'.
//          '104561,1' is out of range of the UInt64 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, _
                                    UInt64.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 UInt64 type.", _
                                    value)         
               End Try
            Next
         Next
      Next                                    
   End Sub
End Module
' The example displays the following output:
'       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 UInt64 type.
'          Unable to parse '-103214,00'.
'          '104561.1' is out of range of the UInt64 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 UInt64 type.
'          Unable to parse '104561.1'.
'          '104561,1' is out of range of the UInt64 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 進値にする必要があります。 有効な 16 進文字は、0 から 9、A から F、および a から f です。 "0x" などのプレフィックスはサポートされていないため、解析操作が失敗します。 と組み合わせることができる他のフラグは 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)

Source:
UInt64.cs
Source:
UInt64.cs
Source:
UInt64.cs

重要

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

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

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

パラメーター

s
ReadOnlySpan<Char>

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

style
NumberStyles

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

provider
IFormatProvider

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

戻り値

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

実装

属性

適用対象

Parse(ReadOnlySpan<Byte>, NumberStyles, IFormatProvider)

Source:
UInt64.cs
Source:
UInt64.cs

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

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

パラメーター

utf8Text
ReadOnlySpan<Byte>

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

style
NumberStyles

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

provider
IFormatProvider

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

戻り値

を解析した utf8Text結果。

実装

適用対象

Parse(String, IFormatProvider)

Source:
UInt64.cs
Source:
UInt64.cs
Source:
UInt64.cs

重要

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

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

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

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

パラメーター

s
String

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

provider
IFormatProvider

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

戻り値

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

実装

属性

例外

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

s パラメーターが正しいスタイルではありません。

パラメーターは sUInt64.MinValue より小さい数値または UInt64.MaxValue より大きい数値を表します。

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

protected void OkToSingle_Click(object sender, EventArgs e)
{
    string locale;
    float 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 = Single.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 OkToSingle_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles OkToSingle.Click
   Dim locale As String
   Dim culture As CultureInfo
   Dim number As Single

   ' 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 = Single.Parse(Me.inputNumber.Text, culture.NumberFormat)
   Catch ex As FormatException
      Exit Sub
   Catch ex As OverflowException
      Exit Sub
   End Try

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

注釈

メソッドの Parse(String, IFormatProvider) このオーバーロードは、通常、さまざまな方法で書式設定できるテキストを値に変換するために UInt64 使用されます。 たとえば、ユーザーが入力したテキストを HTML テキスト ボックスに数値に変換するために使用できます。

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

[ws][sign]digits[ws]

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

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

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

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

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

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

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

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

こちらもご覧ください

適用対象

Parse(String, NumberStyles)

Source:
UInt64.cs
Source:
UInt64.cs
Source:
UInt64.cs

重要

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

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

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

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

パラメーター

s
String

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

style
NumberStyles

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

戻り値

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

属性

例外

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

styleNumberStyles 値ではありません。

- または -

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

s パラメーターの形式が style に準拠していません。

パラメーターは sUInt64.MinValue より小さい数値または UInt64.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 {
               ulong number = UInt64.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 = UInt64.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 ULong = UInt64.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は、現在のカルチャの通貨記号を にsNumberStyles.AllowCurrencySymbol表示できます。
sign 省略可能な記号。 この記号は、 フラグを含む場合styleは のs先頭に表示され、フラグが含まれている場合styleは のs末尾にNumberStyles.AllowTrailingSign表示NumberStyles.AllowLeadingSignできます。 に フラグが含まれている場合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 対応) は、型の UInt64 範囲内にある場合は常に正常に解析されます。 残りの NumberStyles メンバーのほとんどは、入力文字列に存在する可能性がありますが、存在する必要がない要素を制御します。 次の表は、 に存在する可能性がある要素に対する個々 NumberStyles のメンバーの s影響を示しています。

NumberStyles 数字に加えて許可される s 要素
None digits 要素のみ。
AllowDecimalPoint 小数点 (.) 要素と 小数部の要素
AllowExponent 指数表記と exponential_digitsを示す "e" または "E" 文字。
AllowLeadingWhite の先頭sにある ws 要素。
AllowTrailingWhite の末尾sにある ws 要素。
AllowLeadingSign の先頭sにある sign 要素。
AllowTrailingSign の末尾sにある sign 要素。
AllowParentheses 数値を囲むかっこの形式の sign 要素。
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" などのプレフィックスはサポートされていないため、解析操作が失敗します。 パラメーターと組み合わせることができる他の style フラグは NumberStyles.AllowLeadingWhiteNumberStyles.AllowTrailingWhiteのみです。 (列挙には NumberStylesNumberStyles.HexNumber両方の空白フラグを含む複合数値スタイル が含まれています)。

Note

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

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

こちらもご覧ください

適用対象

Parse(ReadOnlySpan<Char>, IFormatProvider)

Source:
UInt64.cs
Source:
UInt64.cs
Source:
UInt64.cs

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

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

パラメーター

s
ReadOnlySpan<Char>

解析する文字のスパン。

provider
IFormatProvider

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

戻り値

を解析した s結果。

実装

適用対象

Parse(ReadOnlySpan<Byte>, IFormatProvider)

Source:
UInt64.cs
Source:
UInt64.cs

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

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

パラメーター

utf8Text
ReadOnlySpan<Byte>

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

provider
IFormatProvider

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

戻り値

を解析した utf8Text結果。

実装

適用対象

Parse(String)

Source:
UInt64.cs
Source:
UInt64.cs
Source:
UInt64.cs

重要

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

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

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

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

パラメーター

s
String

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

戻り値

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

属性

例外

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

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

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

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

string[] values = { "+13230", "-0", "1,390,146", "$190,235,421,127",
                    "0xFA1B", "163042", "-10", "14065839182",
                    "16e07", "134985.0", "-12034" };
foreach (string value in values)
{
   try {
      ulong number = UInt64.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
//       14065839182 --> 14065839182
//       16e07: Bad Format
//       134985.0: Bad Format
//       -12034: Overflow
let values = 
    [| "+13230"; "-0"; "1,390,146"; "$190,235,421,127"
       "0xFA1B"; "163042"; "-10"; "14065839182"
       "16e07"; "134985.0"; "-12034" |]
for value in values do
    try 
        let number = UInt64.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
//       14065839182 --> 14065839182
//       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", "14065839182", _
                           "16e07", "134985.0", "-12034" }
For Each value As String In values
   Try
      Dim number As ULong = UInt64.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
'       14065839182 --> 14065839182
'       16e07: Bad Format
'       134985.0: Bad Format
'       -12034: Overflow

注釈

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

[ws][sign]digits[ws]

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

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

Note

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

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

こちらもご覧ください

適用対象