Condividi tramite


UInt32.Parse Metodo

Definizione

Converte la rappresentazione di stringa di un numero nell'equivalente intero senza segno a 32 bit.

Overload

Nome Descrizione
Parse(String, NumberStyles, IFormatProvider)

Converte la rappresentazione di stringa di un numero in uno stile specificato e in un formato specifico delle impostazioni cultura nell'equivalente intero senza segno a 32 bit.

Parse(ReadOnlySpan<Char>, NumberStyles, IFormatProvider)

Converte la rappresentazione dell'intervallo di un numero in uno stile e in un formato specifico delle impostazioni cultura specificati nell'equivalente intero senza segno a 32 bit.

Parse(ReadOnlySpan<Byte>, NumberStyles, IFormatProvider)

Analizza un intervallo di caratteri UTF-8 in un valore.

Parse(String, IFormatProvider)

Converte la rappresentazione di stringa di un numero in un formato specifico delle impostazioni cultura specificato nell'equivalente intero senza segno a 32 bit.

Parse(ReadOnlySpan<Char>, IFormatProvider)

Analizza un intervallo di caratteri in un valore.

Parse(ReadOnlySpan<Byte>, IFormatProvider)

Analizza un intervallo di caratteri UTF-8 in un valore.

Parse(String)

Converte la rappresentazione di stringa di un numero nell'equivalente intero senza segno a 32 bit.

Parse(String, NumberStyles)

Converte la rappresentazione di stringa di un numero in uno stile specificato nell'equivalente intero senza segno a 32 bit.

Parse(String, NumberStyles, IFormatProvider)

Origine:
UInt32.cs
Origine:
UInt32.cs
Origine:
UInt32.cs
Origine:
UInt32.cs
Origine:
UInt32.cs

Importante

Questa API non è conforme a CLS.

Alternativa conforme a CLS
System.Int64.Parse(String)

Converte la rappresentazione di stringa di un numero in uno stile specificato e in un formato specifico delle impostazioni cultura nell'equivalente intero senza segno a 32 bit.

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

Parametri

s
String

Stringa che rappresenta il numero da convertire. La stringa viene interpretata usando lo stile specificato dal style parametro .

style
NumberStyles

Combinazione bit per bit di valori di enumerazione che indica gli elementi di stile che possono essere presenti in s. Un valore tipico da specificare è Integer.

provider
IFormatProvider

Oggetto che fornisce informazioni di formattazione specifiche delle impostazioni cultura su s.

Restituisce

Intero senza segno a 32 bit equivalente al numero specificato in s.

Implementazioni

Attributi

Eccezioni

style non è un NumberStyles valore.

-o-

style non è una combinazione di AllowHexSpecifier valori e HexNumber .

s non è in un formato conforme a style.

s rappresenta un numero minore di UInt32.MinValue o maggiore di UInt32.MaxValue.

-o-

s include cifre non zero, frazionarie.

Esempio

Nell'esempio seguente viene utilizzato il Parse(String, NumberStyles, IFormatProvider) metodo per convertire varie rappresentazioni di stringa di numeri in valori interi senza segno a 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.

Commenti

Il style parametro definisce gli elementi di stile,ad esempio lo spazio vuoto o il simbolo di segno positivo o negativo, consentiti nel s parametro per l'esito positivo dell'operazione di analisi. Deve essere una combinazione di flag di bit dell'enumerazione NumberStyles .

A seconda del valore di style, il s parametro può includere gli elementi seguenti:

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

Gli elementi tra parentesi quadre ([ e ]) sono facoltativi. Se style include NumberStyles.AllowHexSpecifier, il s parametro può includere gli elementi seguenti:

[ws]hexdigits[ws]

La tabella seguente descrive ogni elemento.

Elemento Descrizione
Ws Spazio vuoto facoltativo. Gli spazi vuoti possono essere visualizzati all'inizio di s se include il NumberStyles.AllowLeadingWhite flag e possono essere visualizzati alla fine di s se style include il NumberStyles.AllowTrailingWhite flag .style
$ Simbolo di valuta specifico delle impostazioni cultura. La posizione nella stringa è definita dalla CurrencyPositivePattern proprietà dell'oggetto NumberFormatInfo restituito dal GetFormat metodo del provider parametro . Il simbolo di valuta può essere visualizzato in s se style include il NumberStyles.AllowCurrencySymbol flag .
segno Segno facoltativo. Il metodo genera un'eccezione OverflowException se s include un segno negativo e rappresenta un numero diverso da zero. Il segno può essere visualizzato all'inizio di s se include il NumberStyles.AllowLeadingSign flag e può apparire la fine di s se style include il NumberStyles.AllowTrailingSignstyle flag. Le parentesi possono essere usate in s per indicare un valore negativo se style include il NumberStyles.AllowParentheses flag .
Cifre Sequenza di cifre da 0 a 9.
. Simbolo di virgola decimale specifica delle impostazioni cultura. Il simbolo del separatore decimale delle impostazioni cultura corrente può essere visualizzato in s se style include il NumberStyles.AllowDecimalPoint flag .
Cifre_frazionarie Una o più occorrenze della cifra 0-9 se style include il NumberStyles.AllowExponent flag o una o più occorrenze della cifra 0 se non lo fa. Le cifre frazionarie possono essere visualizzate solo s se style include il NumberStyles.AllowDecimalPoint flag .
E Carattere "e" o "E", che indica che il valore è rappresentato nella notazione esponenziale (scientifica). Il s parametro può rappresentare un numero in notazione esponenziale se style include il NumberStyles.AllowExponent flag .
exponential_digits Sequenza di cifre da 0 a 9. Il s parametro può rappresentare un numero in notazione esponenziale se style include il NumberStyles.AllowExponent flag .
hexdigits Sequenza di cifre esadecimali da 0 a f o da 0 a F.

Nota

Qualsiasi carattere di terminazione NUL (U+0000) in s viene ignorato dall'operazione di analisi, indipendentemente dal valore dell'argomento style .

Una stringa con solo cifre decimali (che corrisponde allo NumberStyles.None stile) analizza sempre correttamente. La maggior parte degli elementi di controllo membri rimanenti NumberStyles che possono essere presenti, ma non devono essere presenti, in questa stringa di input. La tabella seguente indica in che modo i singoli NumberStyles membri influiscono sugli elementi che possono essere presenti in s.

Valori non compositi NumberStyles Elementi consentiti oltre s alle cifre
NumberStyles.None Solo cifre decimali.
NumberStyles.AllowDecimalPoint Il separatore decimale (.) e gli elementi fractional_digits . Tuttavia, se lo stile non include il NumberStyles.AllowExponent flag, fractional_digits deve essere costituito da una o più cifre 0. In caso contrario, viene generata un'eccezione OverflowException .
NumberStyles.AllowExponent Carattere "e" o "E", che indica la notazione esponenziale, insieme a exponential_digits.
NumberStyles.AllowLeadingWhite Elemento ws all'inizio di s.
NumberStyles.AllowTrailingWhite Elemento ws alla fine di s.
NumberStyles.AllowLeadingSign Segno prima delle cifre.
NumberStyles.AllowTrailingSign Segno dopo le cifre.
NumberStyles.AllowParentheses Parentesi prima e dopo le cifre per indicare un valore negativo.
NumberStyles.AllowThousands Elemento separatore di gruppo (,).
NumberStyles.AllowCurrencySymbol Elemento currency ($).

Se viene usato il NumberStyles.AllowHexSpecifier flag, s deve essere un valore esadecimale. Gli unici flag che possono essere combinati con esso sono NumberStyles.AllowLeadingWhite e NumberStyles.AllowTrailingWhite. L'enumerazione NumberStyles include uno stile numerico composito, NumberStyles.HexNumber, che include entrambi i flag di spazio vuoto.

Nota

Se il s parametro è la rappresentazione di stringa di un numero esadecimale, non può essere preceduto da alcuna decorazione (ad esempio 0x o &h) che la differenzia come numero esadecimale. In questo modo, l'operazione di analisi genera un'eccezione.

Il parametro è un'implementazione il cui metodo restituisce un NumberFormatInfo oggetto che fornisce informazioni specifiche delle impostazioni cultura sul formato di s.GetFormatproviderIFormatProvider Esistono tre modi per usare il provider parametro per fornire informazioni di formattazione personalizzate all'operazione di analisi:

  • È possibile passare l'oggetto effettivo NumberFormatInfo che fornisce informazioni di formattazione. La sua implementazione di GetFormat restituisce semplicemente se stessa.

  • È possibile passare un CultureInfo oggetto che specifica le impostazioni cultura di cui utilizzare la formattazione. La proprietà NumberFormat fornisce informazioni di formattazione.

  • È possibile passare un'implementazione personalizzata IFormatProvider . Il GetFormat metodo deve creare un'istanza e restituire l'oggetto NumberFormatInfo che fornisce informazioni di formattazione.

Se provider è null, viene utilizzato l'oggetto NumberFormatInfo per le impostazioni cultura correnti.

Vedi anche

Si applica a

Parse(ReadOnlySpan<Char>, NumberStyles, IFormatProvider)

Origine:
UInt32.cs
Origine:
UInt32.cs
Origine:
UInt32.cs
Origine:
UInt32.cs
Origine:
UInt32.cs

Importante

Questa API non è conforme a CLS.

Converte la rappresentazione dell'intervallo di un numero in uno stile e in un formato specifico delle impostazioni cultura specificati nell'equivalente intero senza segno a 32 bit.

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

Parametri

s
ReadOnlySpan<Char>

Intervallo contenente i caratteri che rappresentano il numero da convertire. L'intervallo viene interpretato utilizzando lo stile specificato dal style parametro .

style
NumberStyles

Combinazione bit per bit di valori di enumerazione che indica gli elementi di stile che possono essere presenti in s. Un valore tipico da specificare è Integer.

provider
IFormatProvider

Oggetto che fornisce informazioni di formattazione specifiche delle impostazioni cultura su s.

Restituisce

Intero senza segno a 32 bit equivalente al numero specificato in s.

Implementazioni

Attributi

Si applica a

Parse(ReadOnlySpan<Byte>, NumberStyles, IFormatProvider)

Origine:
UInt32.cs
Origine:
UInt32.cs
Origine:
UInt32.cs
Origine:
UInt32.cs

Analizza un intervallo di caratteri UTF-8 in un valore.

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

Parametri

utf8Text
ReadOnlySpan<Byte>

Intervallo di caratteri UTF-8 da analizzare.

style
NumberStyles

Combinazione bit per bit di stili numerici che possono essere presenti in utf8Text.

provider
IFormatProvider

Oggetto che fornisce informazioni di formattazione specifiche delle impostazioni cultura su utf8Text.

Restituisce

Risultato dell'analisi utf8Textdi .

Implementazioni

Si applica a

Parse(String, IFormatProvider)

Origine:
UInt32.cs
Origine:
UInt32.cs
Origine:
UInt32.cs
Origine:
UInt32.cs
Origine:
UInt32.cs

Importante

Questa API non è conforme a CLS.

Alternativa conforme a CLS
System.Int64.Parse(String)

Converte la rappresentazione di stringa di un numero in un formato specifico delle impostazioni cultura specificato nell'equivalente intero senza segno a 32 bit.

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

Parametri

s
String

Stringa che rappresenta il numero da convertire.

provider
IFormatProvider

Oggetto che fornisce informazioni di formattazione specifiche delle impostazioni cultura su s.

Restituisce

Intero senza segno a 32 bit equivalente al numero specificato in s.

Implementazioni

Attributi

Eccezioni

s non è nello stile corretto.

s rappresenta un numero minore di UInt32.MinValue o maggiore di UInt32.MaxValue.

Esempio

L'esempio seguente è il gestore eventi click del pulsante di un modulo Web. Usa la matrice restituita dalla HttpRequest.UserLanguages proprietà per determinare le impostazioni locali dell'utente. Crea quindi un'istanza di un CultureInfo oggetto che corrisponde a tale impostazione locale. L'oggetto NumberFormatInfo che appartiene a tale CultureInfo oggetto viene quindi passato al Parse(String, IFormatProvider) metodo per convertire l'input dell'utente in un UInt32 valore.

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

Commenti

Il s parametro contiene un numero di form:

[ws][sign]digits[ws]

Gli elementi tra parentesi quadre ([ e ]) sono facoltativi. La tabella seguente descrive ogni elemento.

Elemento Descrizione
Ws Spazio vuoto facoltativo.
segno Segno facoltativo o segno negativo se s rappresenta il valore zero.
Cifre Sequenza di cifre compresa tra 0 e 9.

Il parametro s viene interpretato usando lo NumberStyles.Integer stile . Oltre alle cifre decimali del valore intero senza segno, sono consentiti solo spazi iniziali e finali insieme a un segno iniziale. Se il segno negativo è presente, s deve rappresentare un valore pari a zero oppure il metodo genera un'eccezione OverflowException.) Per definire in modo esplicito gli elementi di stile insieme alle informazioni di formattazione specifiche delle impostazioni cultura che possono essere presenti in s, usare il Parse(String, NumberStyles, IFormatProvider) metodo .

Il parametro è un'implementazione il cui metodo restituisce un NumberFormatInfo oggetto che fornisce informazioni specifiche delle impostazioni cultura sul formato di s.GetFormatproviderIFormatProvider Esistono tre modi per usare il provider parametro per fornire informazioni di formattazione personalizzate all'operazione di analisi:

  • È possibile passare l'oggetto effettivo NumberFormatInfo che fornisce informazioni di formattazione. La sua implementazione di GetFormat restituisce semplicemente se stessa.

  • È possibile passare un CultureInfo oggetto che specifica le impostazioni cultura di cui utilizzare la formattazione. La proprietà NumberFormat fornisce informazioni di formattazione.

  • È possibile passare un'implementazione personalizzata IFormatProvider . Il GetFormat metodo deve creare un'istanza e restituire l'oggetto NumberFormatInfo che fornisce informazioni di formattazione.

Se provider è null, viene utilizzato per NumberFormatInfo le impostazioni cultura correnti.

Vedi anche

Si applica a

Parse(ReadOnlySpan<Char>, IFormatProvider)

Origine:
UInt32.cs
Origine:
UInt32.cs
Origine:
UInt32.cs
Origine:
UInt32.cs
Origine:
UInt32.cs

Analizza un intervallo di caratteri in un valore.

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

Parametri

s
ReadOnlySpan<Char>

Intervallo di caratteri da analizzare.

provider
IFormatProvider

Oggetto che fornisce informazioni di formattazione specifiche delle impostazioni cultura su s.

Restituisce

Risultato dell'analisi sdi .

Implementazioni

Si applica a

Parse(ReadOnlySpan<Byte>, IFormatProvider)

Origine:
UInt32.cs
Origine:
UInt32.cs
Origine:
UInt32.cs
Origine:
UInt32.cs

Analizza un intervallo di caratteri UTF-8 in un valore.

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

Parametri

utf8Text
ReadOnlySpan<Byte>

Intervallo di caratteri UTF-8 da analizzare.

provider
IFormatProvider

Oggetto che fornisce informazioni di formattazione specifiche delle impostazioni cultura su utf8Text.

Restituisce

Risultato dell'analisi utf8Textdi .

Implementazioni

Si applica a

Parse(String)

Origine:
UInt32.cs
Origine:
UInt32.cs
Origine:
UInt32.cs
Origine:
UInt32.cs
Origine:
UInt32.cs

Importante

Questa API non è conforme a CLS.

Alternativa conforme a CLS
System.Int64.Parse(String)

Converte la rappresentazione di stringa di un numero nell'equivalente intero senza segno a 32 bit.

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

Parametri

s
String

Stringa che rappresenta il numero da convertire.

Restituisce

Intero senza segno a 32 bit equivalente al numero contenuto in s.

Attributi

Eccezioni

Il s parametro è null.

Il s parametro non è del formato corretto.

Il s parametro rappresenta un numero minore di UInt32.MinValue o maggiore di UInt32.MaxValue.

Esempio

Nell'esempio seguente viene usato il Parse(String) metodo per analizzare una matrice di valori stringa.

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

Commenti

Il s parametro deve essere la rappresentazione di stringa di un numero nel formato seguente.

[ws][sign]digits[ws]

Gli elementi tra parentesi quadre ([ e ]) sono facoltativi. La tabella seguente descrive ogni elemento.

Elemento Descrizione
Ws Spazio vuoto facoltativo.
segno Segno facoltativo. I caratteri di segno validi sono determinati dalle NumberFormatInfo.NegativeSign proprietà e NumberFormatInfo.PositiveSign delle impostazioni cultura correnti. Tuttavia, il simbolo di segno negativo può essere usato solo con zero; in caso contrario, il metodo genera un'eccezione OverflowException.
Cifre Sequenza di cifre compresa tra 0 e 9. Tutti gli zeri iniziali vengono ignorati.

Nota

La stringa specificata dal s parametro viene interpretata utilizzando lo NumberStyles.Integer stile . Non può contenere separatori di gruppo o separatori decimali e non può avere una parte decimale.

Il s parametro viene analizzato usando le informazioni di formattazione in un System.Globalization.NumberFormatInfo oggetto inizializzato per le impostazioni cultura di sistema correnti. Per altre informazioni, vedere NumberFormatInfo.CurrentInfo. Per analizzare una stringa usando le informazioni di formattazione di impostazioni cultura specifiche, usare il Parse(String, IFormatProvider) metodo .

Vedi anche

Si applica a

Parse(String, NumberStyles)

Origine:
UInt32.cs
Origine:
UInt32.cs
Origine:
UInt32.cs
Origine:
UInt32.cs
Origine:
UInt32.cs

Importante

Questa API non è conforme a CLS.

Alternativa conforme a CLS
System.Int64.Parse(String)

Converte la rappresentazione di stringa di un numero in uno stile specificato nell'equivalente intero senza segno a 32 bit.

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

Parametri

s
String

Stringa che rappresenta il numero da convertire. La stringa viene interpretata usando lo stile specificato dal style parametro .

style
NumberStyles

Combinazione bit per bit dei valori di enumerazione che specificano il formato consentito di s. Un valore tipico da specificare è Integer.

Restituisce

Intero senza segno a 32 bit equivalente al numero specificato in s.

Attributi

Eccezioni

style non è un NumberStyles valore.

-o-

style non è una combinazione di AllowHexSpecifier valori e HexNumber .

s non è in un formato conforme a style.

s rappresenta un numero minore di UInt32.MinValue o maggiore di UInt32.MaxValue.

-o-

s include cifre non zero, frazionarie.

Esempio

Nell'esempio seguente viene eseguito un tentativo di analizzare ogni elemento in una matrice di stringhe usando un numero di NumberStyles valori.

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

Commenti

Il style parametro definisce gli elementi di stile(ad esempio spazi vuoti, simbolo di segno positivo o negativo, simbolo separatore di gruppo o simbolo di virgola decimale) consentiti nel s parametro per l'esito positivo dell'operazione di analisi. style deve essere una combinazione di flag di bit dell'enumerazione NumberStyles . Il style parametro rende utile questo overload del metodo quando s contiene la rappresentazione di stringa di un valore esadecimale, quando il sistema numerico (decimale o esadecimale) rappresentato da s è noto solo in fase di esecuzione o quando si desidera impedire lo spazio vuoto o un simbolo di segno in s.

A seconda del valore di style, il s parametro può includere gli elementi seguenti:

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

Gli elementi tra parentesi quadre ([ e ]) sono facoltativi. Se style include NumberStyles.AllowHexSpecifier, il s parametro può contenere gli elementi seguenti:

[ws]hexdigits[ws]

La tabella seguente descrive ogni elemento.

Elemento Descrizione
Ws Spazio vuoto facoltativo. Lo spazio vuoto può essere visualizzato all'inizio di s se include il style flag e può essere visualizzato alla fine di NumberStyles.AllowLeadingWhite se s include il style flag.NumberStyles.AllowTrailingWhite
$ Simbolo di valuta specifico delle impostazioni cultura. La posizione nella stringa è definita dalle NumberFormatInfo.CurrencyNegativePattern proprietà e NumberFormatInfo.CurrencyPositivePattern delle impostazioni cultura correnti. Il simbolo di valuta delle impostazioni cultura corrente può essere visualizzato in s se style include il NumberStyles.AllowCurrencySymbol flag .
segno Segno facoltativo. Il segno può essere visualizzato all'inizio di s se include il style flag e può essere visualizzato alla fine di NumberStyles.AllowLeadingSign se s include il styleNumberStyles.AllowTrailingSign flag. Le parentesi possono essere usate in s per indicare un valore negativo se style include il NumberStyles.AllowParentheses flag . Tuttavia, il simbolo di segno negativo può essere usato solo con zero; in caso contrario, il metodo genera un'eccezione OverflowException.
Cifre

Cifre_frazionarie

exponential_digits
Sequenza di cifre da 0 a 9. Per fractional_digits, è valida solo la cifra 0.
, Simbolo separatore di gruppi specifico delle impostazioni cultura. Il separatore di gruppo delle impostazioni cultura corrente può essere visualizzato in s se style include il NumberStyles.AllowThousands flag .
. Simbolo di virgola decimale specifica delle impostazioni cultura. Il simbolo del separatore decimale delle impostazioni cultura corrente può essere visualizzato in s se style include il NumberStyles.AllowDecimalPoint flag . Solo la cifra 0 può essere visualizzata come cifra frazionaria per l'esito positivo dell'operazione di analisi; se fractional_digits include qualsiasi altra cifra, viene generata un'eccezione FormatException .
E Carattere "e" o "E", che indica che il valore è rappresentato nella notazione esponenziale (scientifica). Il s parametro può rappresentare un numero in notazione esponenziale se style include il NumberStyles.AllowExponent flag .
hexdigits Sequenza di cifre esadecimali da 0 a f o da 0 a F.

Nota

Qualsiasi carattere di terminazione NUL (U+0000) in s viene ignorato dall'operazione di analisi, indipendentemente dal valore dell'argomento style .

Una stringa con solo cifre (che corrisponde allo NumberStyles.None stile) analizza sempre correttamente se si trova nell'intervallo del UInt32 tipo. La maggior parte degli elementi di controllo membri rimanenti NumberStyles che possono essere presenti, ma non devono essere presenti, nella stringa di input. La tabella seguente indica in che modo i singoli NumberStyles membri influiscono sugli elementi che possono essere presenti in s.

Valore della proprietà NumberStyles Elementi consentiti oltre s alle cifre
None Solo l'elemento digits .
AllowDecimalPoint Elementi decimali (.) e frazionari .
AllowExponent Carattere "e" o "E", che indica la notazione esponenziale, insieme a exponential_digits.
AllowLeadingWhite Elemento ws all'inizio di s.
AllowTrailingWhite Elemento ws alla fine di s.
AllowLeadingSign Elemento del segno all'inizio di s.
AllowTrailingSign Elemento del segno alla fine di s.
AllowParentheses Elemento di segno sotto forma di parentesi che racchiudono il valore numerico.
AllowThousands Elemento separatore di gruppo (,).
AllowCurrencySymbol Elemento currency ($).
Currency Tutti gli elementi. Tuttavia, s non può rappresentare un numero esadecimale o un numero in notazione esponenziale.
Float L'elemento ws all'inizio o alla fine di s, firma all'inizio di se il simbolo decimale (.). Il s parametro può anche usare la notazione esponenziale.
Number Elementi ws, , signseparatore di gruppo (,) e separatore decimale (.).
Any Tutti gli elementi. Tuttavia, s non può rappresentare un numero esadecimale.

A differenza degli altri NumberStyles valori, che consentono, ma non richiedono, la presenza di particolari elementi di stile in s, il NumberStyles.AllowHexSpecifier valore dello stile significa che i singoli caratteri numerici in s vengono sempre interpretati come caratteri esadecimali. I caratteri esadecimali validi sono 0-9, A-F e a-f. Non è consentito un prefisso, ad esempio "0x". Gli unici flag che possono essere combinati con il style parametro sono NumberStyles.AllowLeadingWhite e NumberStyles.AllowTrailingWhite. L'enumerazione NumberStyles include uno stile numerico composito, NumberStyles.HexNumber, che include entrambi i flag di spazio vuoto.

Gli unici flag che possono essere combinati con il style parametro sono NumberStyles.AllowLeadingWhite e NumberStyles.AllowTrailingWhite. L'enumerazione NumberStyles include uno stile numerico composito, NumberStyles.HexNumber, che include entrambi i flag di spazio vuoto.

Nota

Se s è la rappresentazione di stringa di un numero esadecimale, non può essere preceduta da alcuna decorazione (ad esempio 0x o &h) che la differenzia come numero esadecimale. In questo modo la conversione non riesce.

Il s parametro viene analizzato usando le informazioni di formattazione in un NumberFormatInfo oggetto inizializzato per le impostazioni cultura di sistema correnti. Per specificare le impostazioni cultura le cui informazioni di formattazione vengono utilizzate per l'operazione di analisi, chiamare l'overload Parse(String, NumberStyles, IFormatProvider) .

Vedi anche

Si applica a