UInt32.Parse Metode

Definisi

Mengonversi representasi string dari angka ke bilangan bulat tidak bertanda 32-bit yang setara.

Overload

Parse(String, NumberStyles, IFormatProvider)

Mengonversi representasi string angka dalam gaya tertentu dan format khusus budaya ke bilangan bulat tidak bertanda 32-bit yang setara.

Parse(ReadOnlySpan<Char>, NumberStyles, IFormatProvider)

Mengonversi representasi rentang angka dalam gaya tertentu dan format khusus budaya ke bilangan bulat tidak bertanda 32-bit yang setara.

Parse(ReadOnlySpan<Byte>, NumberStyles, IFormatProvider)

Menguraikan rentang karakter UTF-8 ke dalam nilai.

Parse(String, IFormatProvider)

Mengonversi representasi string dari angka dalam format khusus budaya tertentu ke bilangan bulat tidak bertanda 32-bit yang setara.

Parse(String, NumberStyles)

Mengonversi representasi string angka dalam gaya tertentu ke bilangan bulat tidak bertanda 32-bit yang setara.

Parse(ReadOnlySpan<Char>, IFormatProvider)

Mengurai rentang karakter ke dalam nilai.

Parse(ReadOnlySpan<Byte>, IFormatProvider)

Menguraikan rentang karakter UTF-8 ke dalam nilai.

Parse(String)

Mengonversi representasi string dari angka ke bilangan bulat tidak bertanda 32-bit yang setara.

Parse(String, NumberStyles, IFormatProvider)

Sumber:
UInt32.cs
Sumber:
UInt32.cs
Sumber:
UInt32.cs

Penting

API ini bukan kompatibel CLS.

Alternatif kompatibel CLS
System.Int64.Parse(String)

Mengonversi representasi string angka dalam gaya tertentu dan format khusus budaya ke bilangan bulat tidak bertanda 32-bit yang setara.

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

Parameter

s
String

String yang mewakili angka yang akan dikonversi. String ditafsirkan dengan menggunakan gaya yang ditentukan oleh style parameter .

style
NumberStyles

Kombinasi bitwise dari nilai enumerasi yang menunjukkan elemen gaya yang dapat ada di s. Nilai umum yang akan ditentukan adalah Integer.

provider
IFormatProvider

Objek yang memasok informasi pemformatan khusus budaya tentang s.

Mengembalikan

Bilangan bulat 32-bit yang tidak ditandatangani setara dengan angka yang ditentukan dalam s.

Penerapan

Atribut

Pengecualian

sadalah null.

style bukan nilai NumberStyles .

-atau-

style bukan kombinasi nilai AllowHexSpecifier dan HexNumber .

s tidak dalam format yang sesuai dengan style.

s mewakili angka yang kurang dari UInt32.MinValue atau lebih besar dari UInt32.MaxValue.

-atau-

s termasuk bukan nol, digit pecahan.

Contoh

Contoh berikut menggunakan Parse(String, NumberStyles, IFormatProvider) metode untuk mengonversi berbagai representasi string angka menjadi nilai bilangan bulat yang tidak ditandatangani 32-bit.

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.

Keterangan

Parameter style menentukan elemen gaya (seperti spasi kosong atau simbol tanda positif atau negatif) yang diizinkan dalam s parameter agar operasi penguraian berhasil. Ini harus berupa kombinasi bendera bit dari NumberStyles enumerasi.

Bergantung pada nilai style, s parameter dapat mencakup elemen berikut:

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

Elemen dalam tanda kurung siku ([ dan ]) adalah opsional. Jika style menyertakan NumberStyles.AllowHexSpecifier, s parameter dapat menyertakan elemen berikut:

[ws] hexdigits[ws]

Tabel berikut ini menjelaskan setiap elemen.

Elemen Deskripsi
Ws Spasi kosong opsional. Spasi kosong dapat muncul di awal s jika style menyertakan NumberStyles.AllowLeadingWhite bendera, dan dapat muncul di akhir s jika style menyertakan NumberStyles.AllowTrailingWhite bendera.
$ Simbol mata uang khusus budaya. Posisinya dalam string didefinisikan oleh CurrencyPositivePattern properti NumberFormatInfo objek yang dikembalikan oleh GetFormat metode provider parameter . Simbol mata uang dapat muncul jika sstyle menyertakan NumberStyles.AllowCurrencySymbol bendera .
sign Tanda opsional. (Metode ini melemparkan OverflowException jika s menyertakan tanda negatif dan mewakili angka bukan nol.) Tanda dapat muncul di awal s jika style menyertakan NumberStyles.AllowLeadingSign bendera, dan tanda tersebut dapat muncul di akhir s jika style menyertakan NumberStyles.AllowTrailingSign bendera. Tanda kurung dapat digunakan s untuk menunjukkan nilai negatif jika style menyertakan NumberStyles.AllowParentheses bendera .
Digit Urutan digit dari 0 hingga 9.
. Simbol titik desimal khusus budaya. Simbol titik desimal budaya saat ini dapat muncul jika sstyle menyertakan NumberStyles.AllowDecimalPoint bendera .
fractional_digits Satu atau beberapa kemunculan digit 0-9 jika style menyertakan NumberStyles.AllowExponent bendera, atau satu atau beberapa kemunculan digit 0 jika tidak. Digit pecahan dapat muncul s hanya jika style menyertakan NumberStyles.AllowDecimalPoint bendera.
E Karakter "e" atau "E", yang menunjukkan bahwa nilai diwakili dalam notasi eksponensial (ilmiah). Parameter s dapat mewakili angka dalam notasi eksponensial jika style menyertakan NumberStyles.AllowExponent bendera .
exponential_digits Urutan digit dari 0 hingga 9. Parameter s dapat mewakili angka dalam notasi eksponensial jika style menyertakan NumberStyles.AllowExponent bendera .
hexdigits Urutan digit heksadesimal dari 0 hingga f, atau 0 hingga F.

Catatan

Setiap karakter NUL yang mengakhiri (U+0000) di s diabaikan oleh operasi penguraian, terlepas dari style nilai argumen.

String dengan digit desimal saja (yang sesuai dengan NumberStyles.None gaya) selalu berhasil diurai. Sebagian besar elemen kontrol anggota yang tersisa NumberStyles yang mungkin ada, tetapi tidak diharuskan ada, dalam string input ini. Tabel berikut menunjukkan bagaimana anggota individu NumberStyles memengaruhi elemen yang mungkin ada di s.

Nilai non-komposit NumberStyles Elemen yang diizinkan selain s digit
NumberStyles.None Digit desimal saja.
NumberStyles.AllowDecimalPoint Titik desimal (.) dan elemen fractional_digits . Namun, jika gaya tidak menyertakan NumberStyles.AllowExponent bendera, fractional_digits harus terdiri dari hanya satu atau lebih 0 digit; jika tidak, akan OverflowException dilemparkan.
NumberStyles.AllowExponent Karakter "e" atau "E", yang menunjukkan notasi eksponensial, bersama dengan exponential_digits.
NumberStyles.AllowLeadingWhite Elemen ws di awal s.
NumberStyles.AllowTrailingWhite Elemen ws di akhir s.
NumberStyles.AllowLeadingSign Tanda sebelum digit.
NumberStyles.AllowTrailingSign Tanda setelah digit.
NumberStyles.AllowParentheses Tanda kurung sebelum dan sesudah digit untuk menunjukkan nilai negatif.
NumberStyles.AllowThousands Elemen pemisah grup (,).
NumberStyles.AllowCurrencySymbol Elemen mata uang ($).

NumberStyles.AllowHexSpecifier Jika bendera digunakan, s harus berupa nilai heksadesimal. Satu-satunya bendera lain yang dapat digabungkan dengannya adalah NumberStyles.AllowLeadingWhite dan NumberStyles.AllowTrailingWhite. (Enumerasi NumberStyles mencakup gaya angka komposit, NumberStyles.HexNumber, yang mencakup kedua bendera spasi putih.)

Catatan

s Jika parameter adalah representasi string dari angka heksadesimal, parameter tersebut tidak dapat didahului oleh dekorasi apa pun (seperti 0x atau &h) yang membedakannya sebagai angka heksadesimal. Hal ini menyebabkan operasi penguraian melempar pengecualian.

Parameter provider adalah IFormatProvider implementasi yang metodenya GetFormat mengembalikan NumberFormatInfo objek yang menyediakan informasi khusus budaya tentang format s. Ada tiga cara untuk menggunakan provider parameter untuk menyediakan informasi pemformatan kustom ke operasi penguraian:

  • Anda dapat meneruskan objek aktual NumberFormatInfo yang menyediakan informasi pemformatan. (Implementasinya GetFormat hanya mengembalikan dirinya sendiri.)

  • Anda dapat meneruskan CultureInfo objek yang menentukan budaya yang pemformatannya akan digunakan. Propertinya NumberFormat menyediakan informasi pemformatan.

  • Anda dapat melewati implementasi kustom IFormatProvider . Metodenya GetFormat harus membuat instans dan mengembalikan NumberFormatInfo objek yang menyediakan informasi pemformatan.

Jika provider adalah null, NumberFormatInfo objek untuk budaya saat ini digunakan.

Lihat juga

Berlaku untuk

Parse(ReadOnlySpan<Char>, NumberStyles, IFormatProvider)

Sumber:
UInt32.cs
Sumber:
UInt32.cs
Sumber:
UInt32.cs

Penting

API ini bukan kompatibel CLS.

Mengonversi representasi rentang angka dalam gaya tertentu dan format khusus budaya ke bilangan bulat tidak bertanda 32-bit yang setara.

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

Parameter

s
ReadOnlySpan<Char>

Rentang yang berisi karakter yang mewakili angka yang akan dikonversi. Rentang ditafsirkan dengan menggunakan gaya yang ditentukan oleh style parameter .

style
NumberStyles

Kombinasi bitwise dari nilai enumerasi yang menunjukkan elemen gaya yang dapat ada di s. Nilai umum yang akan ditentukan adalah Integer.

provider
IFormatProvider

Objek yang memasok informasi pemformatan khusus budaya tentang s.

Mengembalikan

Bilangan bulat 32-bit yang tidak ditandatangani setara dengan angka yang ditentukan dalam s.

Penerapan

Atribut

Berlaku untuk

Parse(ReadOnlySpan<Byte>, NumberStyles, IFormatProvider)

Sumber:
UInt32.cs
Sumber:
UInt32.cs

Menguraikan rentang karakter UTF-8 ke dalam nilai.

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

Parameter

utf8Text
ReadOnlySpan<Byte>

Rentang karakter UTF-8 untuk diurai.

style
NumberStyles

Kombinasi bitwise gaya angka yang dapat ada di utf8Text.

provider
IFormatProvider

Objek yang menyediakan informasi pemformatan khusus budaya tentang utf8Text.

Mengembalikan

Hasil penguraian utf8Text.

Penerapan

Berlaku untuk

Parse(String, IFormatProvider)

Sumber:
UInt32.cs
Sumber:
UInt32.cs
Sumber:
UInt32.cs

Penting

API ini bukan kompatibel CLS.

Alternatif kompatibel CLS
System.Int64.Parse(String)

Mengonversi representasi string dari angka dalam format khusus budaya tertentu ke bilangan bulat tidak bertanda 32-bit yang setara.

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

Parameter

s
String

String yang mewakili angka yang akan dikonversi.

provider
IFormatProvider

Objek yang memasok informasi pemformatan khusus budaya tentang s.

Mengembalikan

Bilangan bulat 32-bit yang tidak ditandatangani setara dengan angka yang ditentukan dalam s.

Penerapan

Atribut

Pengecualian

sadalah null.

s tidak dalam gaya yang benar.

s mewakili angka yang kurang dari UInt32.MinValue atau lebih besar dari UInt32.MaxValue.

Contoh

Contoh berikut adalah tombol klik penanganan aktivitas formulir Web. Ini menggunakan array yang dikembalikan oleh HttpRequest.UserLanguages properti untuk menentukan lokal pengguna. Kemudian membuat instans CultureInfo objek yang sesuai dengan lokal tersebut. Objek NumberFormatInfo milik CultureInfo objek tersebut kemudian diteruskan ke Parse(String, IFormatProvider) metode untuk mengonversi input pengguna menjadi UInt32 nilai.

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

Keterangan

Parameter s berisi sejumlah formulir:

[ws] [tanda]digits[ws]

Item dalam tanda kurung siku ([ dan ]) bersifat opsional. Tabel berikut ini menjelaskan setiap elemen.

Elemen Deskripsi
Ws Spasi kosong opsional.
sign Tanda opsional, atau tanda negatif jika s mewakili nilai nol.
Digit Urutan digit mulai dari 0 hingga 9.

Parameter s ditafsirkan menggunakan NumberStyles.Integer gaya . Selain digit desimal nilai bilangan bulat yang tidak ditandatangani, hanya spasi di depan dan di belakang bersama dengan tanda di depan yang diizinkan. (Jika tanda negatif ada, s harus mewakili nilai nol, atau metode melempar OverflowException.) Untuk secara eksplisit menentukan elemen gaya bersama dengan informasi pemformatan khusus budaya yang dapat ada di s, gunakan Parse(String, NumberStyles, IFormatProvider) metode .

Parameter provider adalah IFormatProvider implementasi yang metodenya GetFormat mengembalikan NumberFormatInfo objek yang menyediakan informasi khusus budaya tentang format s. Ada tiga cara untuk menggunakan provider parameter untuk menyediakan informasi pemformatan kustom ke operasi penguraian:

  • Anda dapat meneruskan objek aktual NumberFormatInfo yang menyediakan informasi pemformatan. (Implementasinya GetFormat hanya mengembalikan dirinya sendiri.)

  • Anda dapat meneruskan CultureInfo objek yang menentukan budaya yang pemformatannya akan digunakan. Propertinya NumberFormat menyediakan informasi pemformatan.

  • Anda dapat melewati implementasi kustom IFormatProvider . Metodenya GetFormat harus membuat instans dan mengembalikan NumberFormatInfo objek yang menyediakan informasi pemformatan.

Jika provider adalah null, NumberFormatInfo untuk budaya saat ini digunakan.

Lihat juga

Berlaku untuk

Parse(String, NumberStyles)

Sumber:
UInt32.cs
Sumber:
UInt32.cs
Sumber:
UInt32.cs

Penting

API ini bukan kompatibel CLS.

Alternatif kompatibel CLS
System.Int64.Parse(String)

Mengonversi representasi string angka dalam gaya tertentu ke bilangan bulat tidak bertanda 32-bit yang setara.

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

Parameter

s
String

String yang mewakili angka yang akan dikonversi. String ditafsirkan dengan menggunakan gaya yang ditentukan oleh style parameter .

style
NumberStyles

Kombinasi bitwise dari nilai enumerasi yang menentukan format yang diizinkan dari s. Nilai umum yang akan ditentukan adalah Integer.

Mengembalikan

Bilangan bulat 32-bit yang tidak ditandatangani setara dengan angka yang ditentukan dalam s.

Atribut

Pengecualian

sadalah null.

style bukan nilai NumberStyles .

-atau-

style bukan kombinasi nilai AllowHexSpecifier dan HexNumber .

s tidak dalam format yang sesuai dengan style.

s mewakili angka yang kurang dari UInt32.MinValue atau lebih besar dari UInt32.MaxValue.

-atau-

s termasuk bukan nol, digit pecahan.

Contoh

Contoh berikut mencoba mengurai setiap elemen dalam array string dengan menggunakan sejumlah NumberStyles nilai.

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

Keterangan

Parameter style menentukan elemen gaya (seperti spasi putih, simbol tanda positif atau negatif, simbol pemisah grup, atau simbol titik desimal) yang diizinkan dalam s parameter agar operasi penguraian berhasil. style harus berupa kombinasi bendera bit dari NumberStyles enumerasi. Parameter style membuat metode ini kelebihan beban berguna ketika s berisi representasi string dari nilai heksadesimal, ketika sistem angka (desimal atau heksadesimal) yang diwakili oleh s hanya diketahui pada durasi, atau ketika Anda ingin melarang spasi putih atau simbol tanda di s.

Bergantung pada nilai style, s parameter dapat mencakup elemen berikut:

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

Elemen dalam tanda kurung siku ([ dan ]) adalah opsional. Jika style menyertakan NumberStyles.AllowHexSpecifier, s parameter mungkin berisi elemen berikut:

[ws] hexdigits[ws]

Tabel berikut ini menjelaskan setiap elemen.

Elemen Deskripsi
Ws Spasi kosong opsional. Spasi kosong dapat muncul di awal s jika style menyertakan NumberStyles.AllowLeadingWhite bendera, dan dapat muncul di akhir s jika style menyertakan NumberStyles.AllowTrailingWhite bendera.
$ Simbol mata uang khusus budaya. Posisinya dalam string didefinisikan oleh NumberFormatInfo.CurrencyNegativePattern properti dan NumberFormatInfo.CurrencyPositivePattern dari budaya saat ini. Simbol mata uang budaya saat ini dapat muncul jika sstyle menyertakan NumberStyles.AllowCurrencySymbol bendera .
sign Tanda opsional. Tanda dapat muncul di awal s jika style menyertakan NumberStyles.AllowLeadingSign bendera, dan dapat muncul di akhir s jika style menyertakan NumberStyles.AllowTrailingSign bendera. Tanda kurung dapat digunakan s untuk menunjukkan nilai negatif jika style menyertakan NumberStyles.AllowParentheses bendera . Namun, simbol tanda negatif hanya dapat digunakan dengan nol; jika tidak, metode melempar OverflowException.
Digit

fractional_digits

exponential_digits
Urutan digit dari 0 hingga 9. Untuk fractional_digits, hanya digit 0 yang valid.
, Simbol pemisah grup khusus budaya. Pemisah grup budaya saat ini dapat muncul jika sstyle menyertakan NumberStyles.AllowThousands bendera .
. Simbol titik desimal khusus budaya. Simbol titik desimal budaya saat ini dapat muncul jika sstyle menyertakan NumberStyles.AllowDecimalPoint bendera . Hanya digit 0 yang dapat muncul sebagai digit pecahan agar operasi penguraian berhasil; jika fractional_digits menyertakan digit lain, akan FormatException dilemparkan.
E Karakter "e" atau "E", yang menunjukkan bahwa nilai diwakili dalam notasi eksponensial (ilmiah). Parameter s dapat mewakili angka dalam notasi eksponensial jika style menyertakan NumberStyles.AllowExponent bendera .
hexdigits Urutan digit heksadesimal dari 0 hingga f, atau 0 hingga F.

Catatan

Setiap karakter NUL yang mengakhiri (U+0000) di s diabaikan oleh operasi penguraian, terlepas dari style nilai argumen.

String dengan digit saja (yang sesuai dengan NumberStyles.None gaya) selalu berhasil diurai jika berada dalam rentang UInt32 jenis. Sebagian besar elemen kontrol anggota yang tersisa NumberStyles yang mungkin ada, tetapi tidak diharuskan ada, dalam string input. Tabel berikut menunjukkan bagaimana anggota individu NumberStyles memengaruhi elemen yang mungkin ada di s.

NumberStyles nilai Elemen yang diizinkan selain s digit
None Elemen digit saja.
AllowDecimalPoint Elemen titik desimal (.) dan fractional-digits .
AllowExponent Karakter "e" atau "E", yang menunjukkan notasi eksponensial, bersama dengan exponential_digits.
AllowLeadingWhite Elemen ws di awal s.
AllowTrailingWhite Elemen ws di akhir s.
AllowLeadingSign Elemen tanda di awal s.
AllowTrailingSign Elemen tanda di akhir s.
AllowParentheses Elemen tanda dalam bentuk tanda kurung yang menyertakan nilai numerik.
AllowThousands Elemen pemisah grup (,).
AllowCurrencySymbol Elemen mata uang ($).
Currency Semua elemen. Namun, s tidak dapat mewakili angka heksadesimal atau angka dalam notasi eksponensial.
Float Elemen ws di awal atau akhir , standa di awal s, dan simbol titik desimal (.). Parameter s juga dapat menggunakan notasi eksponensial.
Number Elemen ws, sign, pemisah grup (,), dan desimal (.).
Any Semua elemen. Namun, s tidak dapat mewakili angka heksadesimal.

Tidak seperti nilai lain NumberStyles , yang memungkinkan, tetapi tidak diperlukan, keberadaan elemen gaya tertentu dalam s, NumberStyles.AllowHexSpecifier nilai gaya berarti bahwa karakter numerik individu di selalu ditafsirkan s sebagai karakter heksadesimal. Karakter heksadesimal yang valid adalah 0-9, A-F, dan a-f. Awalan, seperti "0x", tidak diperbolehkan. Satu-satunya bendera lain yang dapat dikombinasikan dengan style parameter adalah NumberStyles.AllowLeadingWhite dan NumberStyles.AllowTrailingWhite. (Enumerasi NumberStyles mencakup gaya angka komposit, NumberStyles.HexNumber, yang mencakup kedua bendera spasi putih.)

Satu-satunya bendera lain yang dapat dikombinasikan dengan style parameter adalah NumberStyles.AllowLeadingWhite dan NumberStyles.AllowTrailingWhite. (Enumerasi NumberStyles mencakup gaya angka komposit, NumberStyles.HexNumber, yang mencakup kedua bendera spasi putih.)

Catatan

Jika s merupakan representasi string dari angka heksadesimal, itu tidak dapat didahului oleh dekorasi apa pun (seperti 0x atau &h) yang membedakannya sebagai angka heksadesimal. Hal ini menyebabkan konversi gagal.

Parameter s diurai dengan menggunakan informasi pemformatan dalam objek yang diinisialisasi NumberFormatInfo untuk budaya sistem saat ini. Untuk menentukan budaya yang informasi pemformatannya digunakan untuk operasi penguraian, panggil Parse(String, NumberStyles, IFormatProvider) kelebihan beban.

Lihat juga

Berlaku untuk

Parse(ReadOnlySpan<Char>, IFormatProvider)

Sumber:
UInt32.cs
Sumber:
UInt32.cs
Sumber:
UInt32.cs

Mengurai rentang karakter ke dalam nilai.

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

Parameter

s
ReadOnlySpan<Char>

Rentang karakter untuk diurai.

provider
IFormatProvider

Objek yang menyediakan informasi pemformatan khusus budaya tentang s.

Mengembalikan

Hasil penguraian s.

Penerapan

Berlaku untuk

Parse(ReadOnlySpan<Byte>, IFormatProvider)

Sumber:
UInt32.cs
Sumber:
UInt32.cs

Menguraikan rentang karakter UTF-8 ke dalam nilai.

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

Parameter

utf8Text
ReadOnlySpan<Byte>

Rentang karakter UTF-8 untuk diurai.

provider
IFormatProvider

Objek yang menyediakan informasi pemformatan khusus budaya tentang utf8Text.

Mengembalikan

Hasil penguraian utf8Text.

Penerapan

Berlaku untuk

Parse(String)

Sumber:
UInt32.cs
Sumber:
UInt32.cs
Sumber:
UInt32.cs

Penting

API ini bukan kompatibel CLS.

Alternatif kompatibel CLS
System.Int64.Parse(String)

Mengonversi representasi string dari angka ke bilangan bulat tidak bertanda 32-bit yang setara.

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

Parameter

s
String

String yang mewakili angka yang akan dikonversi.

Mengembalikan

Bilangan bulat yang tidak ditandatangani 32-bit setara dengan angka yang terkandung dalam s.

Atribut

Pengecualian

Parameternya s adalah null.

Parameter s bukan format yang benar.

Parameter s mewakili angka yang kurang dari UInt32.MinValue atau lebih besar dari UInt32.MaxValue.

Contoh

Contoh berikut menggunakan Parse(String) metode untuk mengurai array nilai 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

Keterangan

Parameter s harus menjadi representasi string dari angka dalam formulir berikut.

[ws] [tanda]digits[ws]

Elemen dalam tanda kurung siku ([ dan ]) adalah opsional. Tabel berikut ini menjelaskan setiap elemen.

Elemen Deskripsi
Ws Spasi kosong opsional.
sign Tanda opsional. Karakter tanda yang valid ditentukan oleh NumberFormatInfo.NegativeSign properti dan NumberFormatInfo.PositiveSign dari budaya saat ini. Namun, simbol tanda negatif hanya dapat digunakan dengan nol; jika tidak, metode melempar OverflowException.
Digit Urutan digit mulai dari 0 hingga 9. Setiap nol di depan diabaikan.

Catatan

String yang ditentukan oleh s parameter ditafsirkan dengan menggunakan NumberStyles.Integer gaya . Ini tidak boleh berisi pemisah grup atau pemisah desimal, dan tidak dapat memiliki bagian desimal.

Parameter s diurai dengan menggunakan informasi pemformatan dalam objek yang diinisialisasi System.Globalization.NumberFormatInfo untuk budaya sistem saat ini. Untuk informasi selengkapnya, lihat NumberFormatInfo.CurrentInfo. Untuk mengurai string dengan menggunakan informasi pemformatan budaya tertentu, gunakan metode .Parse(String, IFormatProvider)

Lihat juga

Berlaku untuk