UInt64.Parse Methode
Definitie
Belangrijk
Bepaalde informatie heeft betrekking op een voorlopige productversie die aanzienlijk kan worden gewijzigd voordat deze wordt uitgebracht. Microsoft biedt geen enkele expliciete of impliciete garanties met betrekking tot de informatie die hier wordt verstrekt.
Converteert de tekenreeksweergave van een getal naar het 64-bits equivalent van een niet-ondertekend geheel getal.
Overloads
| Name | Description |
|---|---|
| Parse(String, NumberStyles, IFormatProvider) |
Converteert de tekenreeksweergave van een getal in een opgegeven stijl en cultuurspecifieke notatie naar het 64-bits equivalent van niet-ondertekende gehele getallen. |
| Parse(ReadOnlySpan<Char>, NumberStyles, IFormatProvider) |
Converteert de spanweergave van een getal in een opgegeven stijl en cultuurspecifieke indeling naar het 64-bits equivalent van niet-ondertekende gehele getallen. |
| Parse(ReadOnlySpan<Byte>, NumberStyles, IFormatProvider) |
Parseert een reeks UTF-8 tekens in een waarde. |
| Parse(String, IFormatProvider) |
Converteert de tekenreeksweergave van een getal in een opgegeven cultuurspecifieke indeling naar het 64-bits equivalent van het niet-ondertekende gehele getal. |
| Parse(ReadOnlySpan<Char>, IFormatProvider) |
Parseert een reeks tekens in een waarde. |
| Parse(ReadOnlySpan<Byte>, IFormatProvider) |
Parseert een reeks UTF-8 tekens in een waarde. |
| Parse(String) |
Converteert de tekenreeksweergave van een getal naar het 64-bits equivalent van een niet-ondertekend geheel getal. |
| Parse(String, NumberStyles) |
Converteert de tekenreeksweergave van een getal in een opgegeven stijl naar het 64-bits equivalent van het niet-ondertekende gehele getal. |
Parse(String, NumberStyles, IFormatProvider)
- Bron:
- UInt64.cs
- Bron:
- UInt64.cs
- Bron:
- UInt64.cs
- Bron:
- UInt64.cs
- Bron:
- UInt64.cs
Converteert de tekenreeksweergave van een getal in een opgegeven stijl en cultuurspecifieke notatie naar het 64-bits equivalent van niet-ondertekende gehele getallen.
public:
static System::UInt64 Parse(System::String ^ s, System::Globalization::NumberStyles style, IFormatProvider ^ provider);
public:
static System::UInt64 Parse(System::String ^ s, System::Globalization::NumberStyles style, IFormatProvider ^ provider) = System::Numerics::INumberBase<System::UInt64>::Parse;
[System.CLSCompliant(false)]
public static ulong Parse(string s, System.Globalization.NumberStyles style, IFormatProvider provider);
public static ulong Parse(string s, System.Globalization.NumberStyles style, IFormatProvider? provider);
[System.CLSCompliant(false)]
public static ulong Parse(string s, System.Globalization.NumberStyles style, IFormatProvider? provider);
[<System.CLSCompliant(false)>]
static member Parse : string * System.Globalization.NumberStyles * IFormatProvider -> uint64
static member Parse : string * System.Globalization.NumberStyles * IFormatProvider -> uint64
Public Shared Function Parse (s As String, style As NumberStyles, provider As IFormatProvider) As ULong
Parameters
- s
- String
Een tekenreeks die het getal vertegenwoordigt dat moet worden geconverteerd. De tekenreeks wordt geïnterpreteerd met behulp van de stijl die is opgegeven door de style parameter.
- style
- NumberStyles
Een bitsgewijze combinatie van opsommingswaarden die de stijlelementen aangeeft die aanwezig kunnen zijn in s. Een typische waarde die moet worden opgegeven, is Integer.
- provider
- IFormatProvider
Een object dat cultuurspecifieke opmaakinformatie over slevert.
Retouren
Een 64-bits niet-ondertekend geheel getal dat gelijk is aan het getal dat is opgegeven in s.
Implementeringen
- Kenmerken
Uitzonderingen
De s parameter is null.
style is geen NumberStyles waarde.
– of –
style is geen combinatie van AllowHexSpecifier en HexNumber waarden.
De s parameter heeft geen indeling die compatibel is met style.
De s parameter vertegenwoordigt een getal kleiner dan UInt64.MinValue of hoger dan UInt64.MaxValue.
– of –
s bevat niet-nul, fractionele cijfers.
Voorbeelden
In het volgende voorbeeld wordt de Parse(String, NumberStyles, IFormatProvider) methode gebruikt om verschillende tekenreeksweergaven van getallen te converteren naar 64-bits niet-ondertekende gehele getallen.
using System;
using System.Globalization;
public class Example
{
public static void Main()
{
string[] cultureNames= { "en-US", "fr-FR" };
NumberStyles[] styles= { NumberStyles.Integer,
NumberStyles.Integer | NumberStyles.AllowDecimalPoint };
string[] values = { "170209", "+170209.0", "+170209,0", "-103214.00",
"-103214,00", "104561.1", "104561,1" };
// Parse strings using each culture
foreach (string cultureName in cultureNames)
{
CultureInfo ci = new CultureInfo(cultureName);
Console.WriteLine("Parsing strings using the {0} culture",
ci.DisplayName);
// Use each style.
foreach (NumberStyles style in styles)
{
Console.WriteLine(" Style: {0}", style.ToString());
// Parse each numeric string.
foreach (string value in values)
{
try {
Console.WriteLine(" Converted '{0}' to {1}.", value,
UInt64.Parse(value, style, ci));
}
catch (FormatException) {
Console.WriteLine(" Unable to parse '{0}'.", value);
}
catch (OverflowException) {
Console.WriteLine(" '{0}' is out of range of the UInt64 type.",
value);
}
}
}
}
}
}
// The example displays the following output:
// Style: Integer
// Converted '170209' to 170209.
// Unable to parse '+170209.0'.
// Unable to parse '+170209,0'.
// Unable to parse '-103214.00'.
// Unable to parse '-103214,00'.
// Unable to parse '104561.1'.
// Unable to parse '104561,1'.
// Style: Integer, AllowDecimalPoint
// Converted '170209' to 170209.
// Converted '+170209.0' to 170209.
// Unable to parse '+170209,0'.
// '-103214.00' is out of range of the UInt64 type.
// Unable to parse '-103214,00'.
// '104561.1' is out of range of the UInt64 type.
// Unable to parse '104561,1'.
// Parsing strings using the French (France) culture
// Style: Integer
// Converted '170209' to 170209.
// Unable to parse '+170209.0'.
// Unable to parse '+170209,0'.
// Unable to parse '-103214.00'.
// Unable to parse '-103214,00'.
// Unable to parse '104561.1'.
// Unable to parse '104561,1'.
// Style: Integer, AllowDecimalPoint
// Converted '170209' to 170209.
// Unable to parse '+170209.0'.
// Converted '+170209,0' to 170209.
// Unable to parse '-103214.00'.
// '-103214,00' is out of range of the UInt64 type.
// Unable to parse '104561.1'.
// '104561,1' is out of range of the UInt64 type.
open System
open System.Globalization
let cultureNames = [| "en-US"; "fr-FR" |]
let styles = [| NumberStyles.Integer; NumberStyles.Integer ||| NumberStyles.AllowDecimalPoint |]
let values =
[| "170209"; "+170209.0"; "+170209,0"; "-103214.00"
"-103214,00"; "104561.1"; "104561,1" |]
// Parse strings using each culture
for cultureName in cultureNames do
let ci = CultureInfo cultureName
printfn $"Parsing strings using the {ci.DisplayName} culture"
// Use each style.
for style in styles do
printfn $" Style: {style}"
// Parse each numeric string.
for value in values do
try
printfn $" Converted '{value}' to {UInt64.Parse(value, style, ci)}."
with
| :? FormatException ->
printfn $" Unable to parse '{value}'."
| :? OverflowException ->
printfn $" '{value}' is out of range of the UInt64 type."
// The example displays the following output:
// Style: Integer
// Converted '170209' to 170209.
// Unable to parse '+170209.0'.
// Unable to parse '+170209,0'.
// Unable to parse '-103214.00'.
// Unable to parse '-103214,00'.
// Unable to parse '104561.1'.
// Unable to parse '104561,1'.
// Style: Integer, AllowDecimalPoint
// Converted '170209' to 170209.
// Converted '+170209.0' to 170209.
// Unable to parse '+170209,0'.
// '-103214.00' is out of range of the UInt64 type.
// Unable to parse '-103214,00'.
// '104561.1' is out of range of the UInt64 type.
// Unable to parse '104561,1'.
// Parsing strings using the French (France) culture
// Style: Integer
// Converted '170209' to 170209.
// Unable to parse '+170209.0'.
// Unable to parse '+170209,0'.
// Unable to parse '-103214.00'.
// Unable to parse '-103214,00'.
// Unable to parse '104561.1'.
// Unable to parse '104561,1'.
// Style: Integer, AllowDecimalPoint
// Converted '170209' to 170209.
// Unable to parse '+170209.0'.
// Converted '+170209,0' to 170209.
// Unable to parse '-103214.00'.
// '-103214,00' is out of range of the UInt64 type.
// Unable to parse '104561.1'.
// '104561,1' is out of range of the UInt64 type.
Imports System.Globalization
Module Example
Public Sub Main()
Dim cultureNames() As String = { "en-US", "fr-FR" }
Dim styles() As NumberStyles = { NumberStyles.Integer, _
NumberStyles.Integer Or NumberStyles.AllowDecimalPoint }
Dim values() As String = { "170209", "+170209.0", "+170209,0", "-103214.00", _
"-103214,00", "104561.1", "104561,1" }
' Parse strings using each culture
For Each cultureName As String In cultureNames
Dim ci As New CultureInfo(cultureName)
Console.WriteLine("Parsing strings using the {0} culture", ci.DisplayName)
' Use each style.
For Each style As NumberStyles In styles
Console.WriteLine(" Style: {0}", style.ToString())
' Parse each numeric string.
For Each value As String In values
Try
Console.WriteLine(" Converted '{0}' to {1}.", value, _
UInt64.Parse(value, style, ci))
Catch e As FormatException
Console.WriteLine(" Unable to parse '{0}'.", value)
Catch e As OverflowException
Console.WriteLine(" '{0}' is out of range of the UInt64 type.", _
value)
End Try
Next
Next
Next
End Sub
End Module
' The example displays the following output:
' Style: Integer
' Converted '170209' to 170209.
' Unable to parse '+170209.0'.
' Unable to parse '+170209,0'.
' Unable to parse '-103214.00'.
' Unable to parse '-103214,00'.
' Unable to parse '104561.1'.
' Unable to parse '104561,1'.
' Style: Integer, AllowDecimalPoint
' Converted '170209' to 170209.
' Converted '+170209.0' to 170209.
' Unable to parse '+170209,0'.
' '-103214.00' is out of range of the UInt64 type.
' Unable to parse '-103214,00'.
' '104561.1' is out of range of the UInt64 type.
' Unable to parse '104561,1'.
' Parsing strings using the French (France) culture
' Style: Integer
' Converted '170209' to 170209.
' Unable to parse '+170209.0'.
' Unable to parse '+170209,0'.
' Unable to parse '-103214.00'.
' Unable to parse '-103214,00'.
' Unable to parse '104561.1'.
' Unable to parse '104561,1'.
' Style: Integer, AllowDecimalPoint
' Converted '170209' to 170209.
' Unable to parse '+170209.0'.
' Converted '+170209,0' to 170209.
' Unable to parse '-103214.00'.
' '-103214,00' is out of range of the UInt64 type.
' Unable to parse '104561.1'.
' '104561,1' is out of range of the UInt64 type.
Opmerkingen
De style parameter definieert de stijlelementen (zoals witruimte of het positieve of negatieve tekensymbool) die zijn toegestaan in de s parameter om de parseringsbewerking te laten slagen. Dit moet een combinatie zijn van bitvlagmen uit de NumberStyles opsomming.
Afhankelijk van de waarde van style, kan de s parameter de volgende elementen bevatten:
[ws][$][sign]digits[.fractional_digits][E[sign]exponential_digits][ws]
Elementen in vierkante haken ([ en ]) zijn optioneel. Als style dit is opgenomen NumberStyles.AllowHexSpecifier, kan de s parameter de volgende elementen bevatten:
[ws]hexdigits[ws]
In de volgende tabel wordt elk element beschreven.
| Element | Beschrijving |
|---|---|
| Ws | Optionele witruimte. Witruimte kan aan het begin van s de styleNumberStyles.AllowLeadingWhite vlag worden weergegeven en deze kan aan het einde van s de styleNumberStyles.AllowTrailingWhite vlag worden weergegeven. |
| $ | Een cultuurspecifiek valutasymbool. De positie in de tekenreeks wordt gedefinieerd door de CurrencyPositivePattern eigenschap van het NumberFormatInfo object dat wordt geretourneerd door de GetFormat methode van de provider parameter. Het valutasymbool kan worden weergegeven s als style deze de NumberStyles.AllowCurrencySymbol vlag bevat. |
| ondertekenen | Een optioneel teken. (De methode genereert een OverflowException if-teken s met een negatief teken en vertegenwoordigt een getal dat niet nul is.) Het teken kan aan het begin van s de vlag worden weergegeven, styleNumberStyles.AllowLeadingSign en het kan het einde van s de vlag weergeven als style deze de NumberStyles.AllowTrailingSign vlag bevat. Haakjes kunnen worden gebruikt s om een negatieve waarde aan te geven als style deze de NumberStyles.AllowParentheses vlag bevat. |
| Cijfers | Een reeks cijfers van 0 tot en met 9. |
| . | Een cultuurspecifiek decimaalteken. Het decimale puntsymbool van de huidige cultuur kan worden weergegeven s als style deze de NumberStyles.AllowDecimalPoint vlag bevat. |
| fractional_digits | Een of meer exemplaren van het cijfer 0-9 als style deze de NumberStyles.AllowExponent vlag bevat, of een of meer exemplaren van het cijfer 0 als dat niet het geval is. Fractionele cijfers kunnen alleen worden weergegeven als sstyle de NumberStyles.AllowDecimalPoint vlag wordt opgenomen. |
| E | Het teken "e" of "E", dat aangeeft dat de waarde wordt weergegeven in exponentiële (wetenschappelijke) notatie. De s parameter kan een getal in exponentiële notatie vertegenwoordigen als style deze de NumberStyles.AllowExponent vlag bevat. |
| exponential_digits | Een reeks cijfers van 0 tot en met 9. De s parameter kan een getal in exponentiële notatie vertegenwoordigen als style deze de NumberStyles.AllowExponent vlag bevat. |
| hexdigits | Een reeks hexadecimale cijfers van 0 tot en met f of 0 tot en met F. |
Note
Alle nultekens (U+0000) s worden genegeerd door de parseringsbewerking, ongeacht de waarde van het style argument.
Een tekenreeks met alleen decimale cijfers (die overeenkomt met de NumberStyles.None stijl) wordt altijd geparseerd. De meeste resterende NumberStyles leden bepalen elementen die mogelijk aanwezig zijn, maar die niet aanwezig zijn, in deze invoertekenreeks. De volgende tabel geeft aan hoe afzonderlijke NumberStyles leden van invloed zijn op de elementen die aanwezig kunnen zijn in s.
Niet-samengestelde NumberStyles waarden |
Elementen die naast cijfers zijn toegestaan s |
|---|---|
| NumberStyles.None | Alleen decimale cijfers. |
| NumberStyles.AllowDecimalPoint | De decimale punt (.) en fractional_digits elementen. Als de stijl echter niet de NumberStyles.AllowExponent vlag bevat, moet fractional_digits uit slechts één of meer cijfers bestaan; anders wordt er een OverflowException gegenereerd. |
| NumberStyles.AllowExponent | Het teken "e" of "E", dat exponentiële notatie aangeeft, samen met exponential_digits. |
| NumberStyles.AllowLeadingWhite | Het ws-element aan het begin van s. |
| NumberStyles.AllowTrailingWhite | Het ws-element aan het einde van s. |
| NumberStyles.AllowLeadingSign | Een teken voor cijfers. |
| NumberStyles.AllowTrailingSign | Een teken na cijfers. |
| NumberStyles.AllowParentheses | Haakjes voor en na cijfers om een negatieve waarde aan te geven. |
| NumberStyles.AllowThousands | Het groepsscheidingsteken (,) element. |
| NumberStyles.AllowCurrencySymbol | Het valutaelement ($). |
Als de NumberStyles.AllowHexSpecifier vlag wordt gebruikt, s moet dit een hexadecimale waarde zijn. Geldige hexadecimale tekens zijn 0-9, A-F en a-f. Een voorvoegsel zoals '0x' wordt niet ondersteund en zorgt ervoor dat de parseringsbewerking mislukt. De enige andere vlaggen die ermee kunnen worden gecombineerd, zijn NumberStyles.AllowLeadingWhite en NumberStyles.AllowTrailingWhite. (De NumberStyles opsomming bevat een samengestelde getalstijl, NumberStyles.HexNumberdie beide spatievlagmen bevat.)
Note
Als de parameter de s tekenreeksweergave is van een hexadecimaal getal, kan deze niet worden voorafgegaan door een decoratie (zoals 0x of &h) die deze onderscheidt als een hexadecimaal getal. Dit zorgt ervoor dat de parseringsbewerking een uitzondering genereert.
De provider parameter is een IFormatProvider implementatie waarvan de GetFormat methode een NumberFormatInfo object retourneert dat cultuurspecifieke informatie biedt over de indeling van s. Er zijn drie manieren om de provider parameter te gebruiken om aangepaste opmaakgegevens op te geven voor de parseringsbewerking:
U kunt het werkelijke NumberFormatInfo object doorgeven dat opmaakinformatie biedt. (De implementatie van GetFormat simpelweg retourneert zichzelf.)
U kunt een CultureInfo object doorgeven dat de cultuur aangeeft waarvan de opmaak moet worden gebruikt. De NumberFormat eigenschap bevat opmaakgegevens.
U kunt een aangepaste IFormatProvider implementatie doorgeven. De GetFormat methode moet het object instantiëren en retourneren NumberFormatInfo dat opmaakinformatie biedt.
Als provider dat het is null, wordt het NumberFormatInfo object voor de huidige cultuur gebruikt.
Zie ook
Van toepassing op
Parse(ReadOnlySpan<Char>, NumberStyles, IFormatProvider)
- Bron:
- UInt64.cs
- Bron:
- UInt64.cs
- Bron:
- UInt64.cs
- Bron:
- UInt64.cs
- Bron:
- UInt64.cs
Belangrijk
Deze API is niet CLS-conform.
Converteert de spanweergave van een getal in een opgegeven stijl en cultuurspecifieke indeling naar het 64-bits equivalent van niet-ondertekende gehele getallen.
public static ulong Parse(ReadOnlySpan<char> s, System.Globalization.NumberStyles style = System.Globalization.NumberStyles.Integer, IFormatProvider? provider = default);
[System.CLSCompliant(false)]
public static ulong Parse(ReadOnlySpan<char> s, System.Globalization.NumberStyles style = System.Globalization.NumberStyles.Integer, IFormatProvider provider = default);
[System.CLSCompliant(false)]
public static ulong Parse(ReadOnlySpan<char> s, System.Globalization.NumberStyles style = System.Globalization.NumberStyles.Integer, IFormatProvider? provider = default);
static member Parse : ReadOnlySpan<char> * System.Globalization.NumberStyles * IFormatProvider -> uint64
[<System.CLSCompliant(false)>]
static member Parse : ReadOnlySpan<char> * System.Globalization.NumberStyles * IFormatProvider -> uint64
Public Shared Function Parse (s As ReadOnlySpan(Of Char), Optional style As NumberStyles = System.Globalization.NumberStyles.Integer, Optional provider As IFormatProvider = Nothing) As ULong
Parameters
- s
- ReadOnlySpan<Char>
Een bereik met de tekens die het getal vertegenwoordigen dat moet worden geconverteerd. De periode wordt geïnterpreteerd met behulp van de stijl die is opgegeven door de style parameter.
- style
- NumberStyles
Een bitsgewijze combinatie van opsommingswaarden die de stijlelementen aangeeft die aanwezig kunnen zijn in s. Een typische waarde die moet worden opgegeven, is Integer.
- provider
- IFormatProvider
Een object dat cultuurspecifieke opmaakinformatie over slevert.
Retouren
Een 64-bits niet-ondertekend geheel getal dat gelijk is aan het getal dat is opgegeven in s.
Implementeringen
- Kenmerken
Van toepassing op
Parse(ReadOnlySpan<Byte>, NumberStyles, IFormatProvider)
- Bron:
- UInt64.cs
- Bron:
- UInt64.cs
- Bron:
- UInt64.cs
- Bron:
- UInt64.cs
Parseert een reeks UTF-8 tekens in een waarde.
public static ulong Parse(ReadOnlySpan<byte> utf8Text, System.Globalization.NumberStyles style = System.Globalization.NumberStyles.Integer, IFormatProvider? provider = default);
static member Parse : ReadOnlySpan<byte> * System.Globalization.NumberStyles * IFormatProvider -> uint64
Public Shared Function Parse (utf8Text As ReadOnlySpan(Of Byte), Optional style As NumberStyles = System.Globalization.NumberStyles.Integer, Optional provider As IFormatProvider = Nothing) As ULong
Parameters
- utf8Text
- ReadOnlySpan<Byte>
Het bereik van UTF-8 tekens om te parseren.
- style
- NumberStyles
Een bitsgewijze combinatie van getalstijlen die aanwezig kunnen zijn in utf8Text.
- provider
- IFormatProvider
Een object dat cultuurspecifieke opmaakinformatie biedt over utf8Text.
Retouren
Het resultaat van parseren utf8Text.
Implementeringen
Van toepassing op
Parse(String, IFormatProvider)
- Bron:
- UInt64.cs
- Bron:
- UInt64.cs
- Bron:
- UInt64.cs
- Bron:
- UInt64.cs
- Bron:
- UInt64.cs
Converteert de tekenreeksweergave van een getal in een opgegeven cultuurspecifieke indeling naar het 64-bits equivalent van het niet-ondertekende gehele getal.
public:
static System::UInt64 Parse(System::String ^ s, IFormatProvider ^ provider);
public:
static System::UInt64 Parse(System::String ^ s, IFormatProvider ^ provider) = IParsable<System::UInt64>::Parse;
[System.CLSCompliant(false)]
public static ulong Parse(string s, IFormatProvider provider);
public static ulong Parse(string s, IFormatProvider? provider);
[System.CLSCompliant(false)]
public static ulong Parse(string s, IFormatProvider? provider);
[<System.CLSCompliant(false)>]
static member Parse : string * IFormatProvider -> uint64
static member Parse : string * IFormatProvider -> uint64
Public Shared Function Parse (s As String, provider As IFormatProvider) As ULong
Parameters
- s
- String
Een tekenreeks die het getal vertegenwoordigt dat moet worden geconverteerd.
- provider
- IFormatProvider
Een object dat cultuurspecifieke opmaakinformatie over slevert.
Retouren
Een 64-bits niet-ondertekend geheel getal dat gelijk is aan het getal dat is opgegeven in s.
Implementeringen
- Kenmerken
Uitzonderingen
De s parameter is null.
De s parameter bevindt zich niet in de juiste stijl.
De s parameter vertegenwoordigt een getal kleiner dan UInt64.MinValue of hoger dan UInt64.MaxValue.
Voorbeelden
Het volgende voorbeeld is de knop klik op gebeurtenishandler van een webformulier. Hierbij wordt de matrix gebruikt die door de HttpRequest.UserLanguages eigenschap wordt geretourneerd om de landinstelling van de gebruiker te bepalen. Vervolgens wordt een CultureInfo object geïnstitueert dat overeenkomt met die landinstelling. Het NumberFormatInfo object dat bij dat CultureInfo object hoort, wordt vervolgens doorgegeven aan de Parse(String, IFormatProvider) methode om de invoer van de gebruiker te converteren naar een UInt64 waarde.
protected void OkToSingle_Click(object sender, EventArgs e)
{
string locale;
float number;
CultureInfo culture;
// Return if string is empty
if (String.IsNullOrEmpty(this.inputNumber.Text))
return;
// Get locale of web request to determine possible format of number
if (Request.UserLanguages.Length == 0)
return;
locale = Request.UserLanguages[0];
if (String.IsNullOrEmpty(locale))
return;
// Instantiate CultureInfo object for the user's locale
culture = new CultureInfo(locale);
// Convert user input from a string to a number
try
{
number = Single.Parse(this.inputNumber.Text, culture.NumberFormat);
}
catch (FormatException)
{
return;
}
catch (Exception)
{
return;
}
// Output number to label on web form
this.outputNumber.Text = "Number is " + number.ToString();
}
Protected Sub OkToSingle_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles OkToSingle.Click
Dim locale As String
Dim culture As CultureInfo
Dim number As Single
' Return if string is empty
If String.IsNullOrEmpty(Me.inputNumber.Text) Then Exit Sub
' Get locale of web request to determine possible format of number
If Request.UserLanguages.Length = 0 Then Exit Sub
locale = Request.UserLanguages(0)
If String.IsNullOrEmpty(locale) Then Exit Sub
' Instantiate CultureInfo object for the user's locale
culture = New CultureInfo(locale)
' Convert user input from a string to a number
Try
number = Single.Parse(Me.inputNumber.Text, culture.NumberFormat)
Catch ex As FormatException
Exit Sub
Catch ex As OverflowException
Exit Sub
End Try
' Output number to label on web form
Me.outputNumber.Text = "Number is " & number.ToString()
End Sub
Opmerkingen
Deze overbelasting van de Parse(String, IFormatProvider) methode wordt meestal gebruikt om tekst te converteren die op verschillende manieren kan worden opgemaakt naar een UInt64 waarde. Het kan bijvoorbeeld worden gebruikt om de tekst die door een gebruiker is ingevoerd, te converteren naar een HTML-tekstvak naar een numerieke waarde.
De s parameter bevat een getal van het formulier:
[ws][sign]digits[ws]
Items in vierkante haken ([ en ]) zijn optioneel. In de volgende tabel wordt elk element beschreven.
| Element | Beschrijving |
|---|---|
| Ws | Optionele witruimte. |
| ondertekenen | Een optioneel positief teken of een negatief teken als s de waarde nul aangeeft. |
| Cijfers | Een reeks cijfers tussen 0 en 9. |
De parameter s wordt geïnterpreteerd met behulp van de NumberStyles.Integer stijl. Naast de decimale cijfers van de niet-ondertekende gehele waarde zijn alleen voorloop- en volgspaties toegestaan, samen met een voorloopteken. (Als het negatieve teken aanwezig is, s moet deze een waarde van nul vertegenwoordigen of de methode een OverflowException.) Als u de stijlelementen expliciet wilt definiëren in combinatie met de cultuurspecifieke opmaakinformatie die aanwezig kan zijn s, gebruikt u de Parse(String, NumberStyles, IFormatProvider) methode.
De provider parameter is een IFormatProvider implementatie waarvan de GetFormat methode een NumberFormatInfo object retourneert dat cultuurspecifieke informatie biedt over de indeling van s. Er zijn drie manieren om de provider parameter te gebruiken om aangepaste opmaakgegevens op te geven voor de parseringsbewerking:
U kunt het werkelijke NumberFormatInfo object doorgeven dat opmaakinformatie biedt. (De implementatie van GetFormat simpelweg retourneert zichzelf.)
U kunt een CultureInfo object doorgeven dat de cultuur aangeeft waarvan de opmaak moet worden gebruikt. De NumberFormat eigenschap bevat opmaakgegevens.
U kunt een aangepaste IFormatProvider implementatie doorgeven. De GetFormat methode moet het object instantiëren en retourneren NumberFormatInfo dat opmaakinformatie biedt.
Als provider dat het is null, wordt de NumberFormatInfo voor de huidige cultuur gebruikt.
Zie ook
Van toepassing op
Parse(ReadOnlySpan<Char>, IFormatProvider)
- Bron:
- UInt64.cs
- Bron:
- UInt64.cs
- Bron:
- UInt64.cs
- Bron:
- UInt64.cs
- Bron:
- UInt64.cs
Parseert een reeks tekens in een waarde.
public:
static System::UInt64 Parse(ReadOnlySpan<char> s, IFormatProvider ^ provider) = ISpanParsable<System::UInt64>::Parse;
public static ulong Parse(ReadOnlySpan<char> s, IFormatProvider? provider);
static member Parse : ReadOnlySpan<char> * IFormatProvider -> uint64
Public Shared Function Parse (s As ReadOnlySpan(Of Char), provider As IFormatProvider) As ULong
Parameters
- s
- ReadOnlySpan<Char>
De reeks tekens die moeten worden geparseerd.
- provider
- IFormatProvider
Een object dat cultuurspecifieke opmaakinformatie biedt over s.
Retouren
Het resultaat van parseren s.
Implementeringen
Van toepassing op
Parse(ReadOnlySpan<Byte>, IFormatProvider)
- Bron:
- UInt64.cs
- Bron:
- UInt64.cs
- Bron:
- UInt64.cs
- Bron:
- UInt64.cs
Parseert een reeks UTF-8 tekens in een waarde.
public:
static System::UInt64 Parse(ReadOnlySpan<System::Byte> utf8Text, IFormatProvider ^ provider) = IUtf8SpanParsable<System::UInt64>::Parse;
public static ulong Parse(ReadOnlySpan<byte> utf8Text, IFormatProvider? provider);
static member Parse : ReadOnlySpan<byte> * IFormatProvider -> uint64
Public Shared Function Parse (utf8Text As ReadOnlySpan(Of Byte), provider As IFormatProvider) As ULong
Parameters
- utf8Text
- ReadOnlySpan<Byte>
Het bereik van UTF-8 tekens om te parseren.
- provider
- IFormatProvider
Een object dat cultuurspecifieke opmaakinformatie biedt over utf8Text.
Retouren
Het resultaat van parseren utf8Text.
Implementeringen
Van toepassing op
Parse(String)
- Bron:
- UInt64.cs
- Bron:
- UInt64.cs
- Bron:
- UInt64.cs
- Bron:
- UInt64.cs
- Bron:
- UInt64.cs
Converteert de tekenreeksweergave van een getal naar het 64-bits equivalent van een niet-ondertekend geheel getal.
public:
static System::UInt64 Parse(System::String ^ s);
[System.CLSCompliant(false)]
public static ulong Parse(string s);
public static ulong Parse(string s);
[<System.CLSCompliant(false)>]
static member Parse : string -> uint64
static member Parse : string -> uint64
Public Shared Function Parse (s As String) As ULong
Parameters
- s
- String
Een tekenreeks die het getal vertegenwoordigt dat moet worden geconverteerd.
Retouren
Een 64-bits geheel getal zonder teken dat gelijk is aan het getal in s.
- Kenmerken
Uitzonderingen
De s parameter is null.
De s parameter heeft niet de juiste indeling.
De s parameter vertegenwoordigt een getal kleiner dan UInt64.MinValue of hoger dan UInt64.MaxValue.
Voorbeelden
In het volgende voorbeeld wordt de Parse methode gebruikt om een matrix met tekenreekswaarden te parseren.
string[] values = { "+13230", "-0", "1,390,146", "$190,235,421,127",
"0xFA1B", "163042", "-10", "14065839182",
"16e07", "134985.0", "-12034" };
foreach (string value in values)
{
try {
ulong number = UInt64.Parse(value);
Console.WriteLine("{0} --> {1}", value, number);
}
catch (FormatException) {
Console.WriteLine("{0}: Bad Format", value);
}
catch (OverflowException) {
Console.WriteLine("{0}: Overflow", value);
}
}
// The example displays the following output:
// +13230 --> 13230
// -0 --> 0
// 1,390,146: Bad Format
// $190,235,421,127: Bad Format
// 0xFA1B: Bad Format
// 163042 --> 163042
// -10: Overflow
// 14065839182 --> 14065839182
// 16e07: Bad Format
// 134985.0: Bad Format
// -12034: Overflow
let values =
[| "+13230"; "-0"; "1,390,146"; "$190,235,421,127"
"0xFA1B"; "163042"; "-10"; "14065839182"
"16e07"; "134985.0"; "-12034" |]
for value in values do
try
let number = UInt64.Parse value
printfn $"{value} --> {number}"
with
| :? FormatException ->
printfn $"{value}: Bad Format"
| :? OverflowException ->
printfn $"{value}: Overflow"
// The example displays the following output:
// +13230 --> 13230
// -0 --> 0
// 1,390,146: Bad Format
// $190,235,421,127: Bad Format
// 0xFA1B: Bad Format
// 163042 --> 163042
// -10: Overflow
// 14065839182 --> 14065839182
// 16e07: Bad Format
// 134985.0: Bad Format
// -12034: Overflow
Dim values() As String = { "+13230", "-0", "1,390,146", "$190,235,421,127", _
"0xFA1B", "163042", "-10", "14065839182", _
"16e07", "134985.0", "-12034" }
For Each value As String In values
Try
Dim number As ULong = UInt64.Parse(value)
Console.WriteLine("{0} --> {1}", value, number)
Catch e As FormatException
Console.WriteLine("{0}: Bad Format", value)
Catch e As OverflowException
Console.WriteLine("{0}: Overflow", value)
End Try
Next
' The example displays the following output:
' +13230 --> 13230
' -0 --> 0
' 1,390,146: Bad Format
' $190,235,421,127: Bad Format
' 0xFA1B: Bad Format
' 163042 --> 163042
' -10: Overflow
' 14065839182 --> 14065839182
' 16e07: Bad Format
' 134985.0: Bad Format
' -12034: Overflow
Opmerkingen
De s parameter moet de tekenreeksweergave van een getal zijn in de volgende vorm.
[ws][teken]digits[ws]
Elementen in vierkante haken ([ en ]) zijn optioneel. In de volgende tabel wordt elk element beschreven.
| Element | Beschrijving |
|---|---|
| Ws | Optionele witruimte. |
| ondertekenen | Een optioneel teken. Geldige tekens worden bepaald door de NumberFormatInfo.NegativeSign en NumberFormatInfo.PositiveSign eigenschappen van de huidige cultuur. Het symbool voor een negatief teken kan echter alleen worden gebruikt met nul; anders gooit de methode een OverflowException. |
| Cijfers | Een reeks cijfers tussen 0 en 9. Voorloopnullen worden genegeerd. |
Note
De tekenreeks die door de s parameter is opgegeven, wordt geïnterpreteerd met behulp van de NumberStyles.Integer stijl. Het mag geen groepsscheidingstekens of decimaalteken bevatten en kan geen decimaal gedeelte bevatten.
De s parameter wordt geparseerd met behulp van de opmaakgegevens in een System.Globalization.NumberFormatInfo object dat is geïnitialiseerd voor de huidige systeemcultuur. Zie NumberFormatInfo.CurrentInfo voor meer informatie. Als u een tekenreeks wilt parseren met behulp van de opmaakgegevens van een specifieke cultuur, gebruikt u de Parse(String, IFormatProvider) methode.
Zie ook
Van toepassing op
Parse(String, NumberStyles)
- Bron:
- UInt64.cs
- Bron:
- UInt64.cs
- Bron:
- UInt64.cs
- Bron:
- UInt64.cs
- Bron:
- UInt64.cs
Converteert de tekenreeksweergave van een getal in een opgegeven stijl naar het 64-bits equivalent van het niet-ondertekende gehele getal.
public:
static System::UInt64 Parse(System::String ^ s, System::Globalization::NumberStyles style);
[System.CLSCompliant(false)]
public static ulong Parse(string s, System.Globalization.NumberStyles style);
public static ulong Parse(string s, System.Globalization.NumberStyles style);
[<System.CLSCompliant(false)>]
static member Parse : string * System.Globalization.NumberStyles -> uint64
static member Parse : string * System.Globalization.NumberStyles -> uint64
Public Shared Function Parse (s As String, style As NumberStyles) As ULong
Parameters
- s
- String
Een tekenreeks die het getal vertegenwoordigt dat moet worden geconverteerd. De tekenreeks wordt geïnterpreteerd met behulp van de stijl die is opgegeven door de style parameter.
- style
- NumberStyles
Een bitsgewijze combinatie van de opsommingswaarden die de toegestane notatie van s. Een typische waarde die moet worden opgegeven, is Integer.
Retouren
Een 64-bits niet-ondertekend geheel getal dat gelijk is aan het getal dat is opgegeven in s.
- Kenmerken
Uitzonderingen
De s parameter is null.
style is geen NumberStyles waarde.
– of –
style is geen combinatie van AllowHexSpecifier en HexNumber waarden.
De s parameter heeft geen indeling die compatibel is met style.
De s parameter vertegenwoordigt een getal kleiner dan UInt64.MinValue of hoger dan UInt64.MaxValue.
– of –
s bevat niet-nul, fractionele cijfers.
Voorbeelden
In het volgende voorbeeld wordt geprobeerd om elk element in een tekenreeksmatrix te parseren met behulp van NumberStyles een aantal waarden.
using System;
using System.Globalization;
public class Example
{
public static void Main()
{
string[] values= { " 214309 ", "1,064,181", "(0)", "10241+", " + 21499 ",
" +21499 ", "122153.00", "1e03ff", "91300.0e-2" };
NumberStyles whitespace = NumberStyles.AllowLeadingWhite | NumberStyles.AllowTrailingWhite;
NumberStyles[] styles= { NumberStyles.None, whitespace,
NumberStyles.AllowLeadingSign | NumberStyles.AllowTrailingSign | whitespace,
NumberStyles.AllowThousands | NumberStyles.AllowCurrencySymbol,
NumberStyles.AllowExponent | NumberStyles.AllowDecimalPoint };
// Attempt to convert each number using each style combination.
foreach (string value in values)
{
Console.WriteLine("Attempting to convert '{0}':", value);
foreach (NumberStyles style in styles)
{
try {
ulong number = UInt64.Parse(value, style);
Console.WriteLine(" {0}: {1}", style, number);
}
catch (FormatException) {
Console.WriteLine(" {0}: Bad Format", style);
}
catch (OverflowException)
{
Console.WriteLine(" {0}: Overflow", value);
}
}
Console.WriteLine();
}
}
}
// The example displays the following output:
// Attempting to convert ' 214309 ':
// None: Bad Format
// AllowLeadingWhite, AllowTrailingWhite: 214309
// Integer, AllowTrailingSign: 214309
// AllowThousands, AllowCurrencySymbol: Bad Format
// AllowDecimalPoint, AllowExponent: Bad Format
//
// Attempting to convert '1,064,181':
// None: Bad Format
// AllowLeadingWhite, AllowTrailingWhite: Bad Format
// Integer, AllowTrailingSign: Bad Format
// AllowThousands, AllowCurrencySymbol: 1064181
// AllowDecimalPoint, AllowExponent: Bad Format
//
// Attempting to convert '(0)':
// None: Bad Format
// AllowLeadingWhite, AllowTrailingWhite: Bad Format
// Integer, AllowTrailingSign: Bad Format
// AllowThousands, AllowCurrencySymbol: Bad Format
// AllowDecimalPoint, AllowExponent: Bad Format
//
// Attempting to convert '10241+':
// None: Bad Format
// AllowLeadingWhite, AllowTrailingWhite: Bad Format
// Integer, AllowTrailingSign: 10241
// AllowThousands, AllowCurrencySymbol: Bad Format
// AllowDecimalPoint, AllowExponent: Bad Format
//
// Attempting to convert ' + 21499 ':
// None: Bad Format
// AllowLeadingWhite, AllowTrailingWhite: Bad Format
// Integer, AllowTrailingSign: Bad Format
// AllowThousands, AllowCurrencySymbol: Bad Format
// AllowDecimalPoint, AllowExponent: Bad Format
//
// Attempting to convert ' +21499 ':
// None: Bad Format
// AllowLeadingWhite, AllowTrailingWhite: Bad Format
// Integer, AllowTrailingSign: 21499
// AllowThousands, AllowCurrencySymbol: Bad Format
// AllowDecimalPoint, AllowExponent: Bad Format
//
// Attempting to convert '122153.00':
// None: Bad Format
// AllowLeadingWhite, AllowTrailingWhite: Bad Format
// Integer, AllowTrailingSign: Bad Format
// AllowThousands, AllowCurrencySymbol: Bad Format
// AllowDecimalPoint, AllowExponent: 122153
//
// Attempting to convert '1e03ff':
// None: Bad Format
// AllowLeadingWhite, AllowTrailingWhite: Bad Format
// Integer, AllowTrailingSign: Bad Format
// AllowThousands, AllowCurrencySymbol: Bad Format
// AllowDecimalPoint, AllowExponent: Bad Format
//
// Attempting to convert '91300.0e-2':
// None: Bad Format
// AllowLeadingWhite, AllowTrailingWhite: Bad Format
// Integer, AllowTrailingSign: Bad Format
// AllowThousands, AllowCurrencySymbol: Bad Format
// AllowDecimalPoint, AllowExponent: 913
open System
open System.Globalization
let values =
[| " 214309 "; "1,064,181"; "(0)"; "10241+"; " + 21499 "
" +21499 "; "122153.00"; "1e03ff"; "91300.0e-2" |]
let whitespace = NumberStyles.AllowLeadingWhite ||| NumberStyles.AllowTrailingWhite
let styles =
[| NumberStyles.None; whitespace
NumberStyles.AllowLeadingSign ||| NumberStyles.AllowTrailingSign ||| whitespace
NumberStyles.AllowThousands ||| NumberStyles.AllowCurrencySymbol
NumberStyles.AllowExponent ||| NumberStyles.AllowDecimalPoint |]
// Attempt to convert each number using each style combination.
for value in values do
printfn $"Attempting to convert '{value}':"
for style in styles do
try
let number = UInt64.Parse(value, style)
printfn $" {style}: {number}"
with
| :? FormatException ->
printfn $" {style}: Bad Format"
| :? OverflowException ->
printfn $" {value}: Overflow"
printfn ""
// The example displays the following output:
// Attempting to convert ' 214309 ':
// None: Bad Format
// AllowLeadingWhite, AllowTrailingWhite: 214309
// Integer, AllowTrailingSign: 214309
// AllowThousands, AllowCurrencySymbol: Bad Format
// AllowDecimalPoint, AllowExponent: Bad Format
//
// Attempting to convert '1,064,181':
// None: Bad Format
// AllowLeadingWhite, AllowTrailingWhite: Bad Format
// Integer, AllowTrailingSign: Bad Format
// AllowThousands, AllowCurrencySymbol: 1064181
// AllowDecimalPoint, AllowExponent: Bad Format
//
// Attempting to convert '(0)':
// None: Bad Format
// AllowLeadingWhite, AllowTrailingWhite: Bad Format
// Integer, AllowTrailingSign: Bad Format
// AllowThousands, AllowCurrencySymbol: Bad Format
// AllowDecimalPoint, AllowExponent: Bad Format
//
// Attempting to convert '10241+':
// None: Bad Format
// AllowLeadingWhite, AllowTrailingWhite: Bad Format
// Integer, AllowTrailingSign: 10241
// AllowThousands, AllowCurrencySymbol: Bad Format
// AllowDecimalPoint, AllowExponent: Bad Format
//
// Attempting to convert ' + 21499 ':
// None: Bad Format
// AllowLeadingWhite, AllowTrailingWhite: Bad Format
// Integer, AllowTrailingSign: Bad Format
// AllowThousands, AllowCurrencySymbol: Bad Format
// AllowDecimalPoint, AllowExponent: Bad Format
//
// Attempting to convert ' +21499 ':
// None: Bad Format
// AllowLeadingWhite, AllowTrailingWhite: Bad Format
// Integer, AllowTrailingSign: 21499
// AllowThousands, AllowCurrencySymbol: Bad Format
// AllowDecimalPoint, AllowExponent: Bad Format
//
// Attempting to convert '122153.00':
// None: Bad Format
// AllowLeadingWhite, AllowTrailingWhite: Bad Format
// Integer, AllowTrailingSign: Bad Format
// AllowThousands, AllowCurrencySymbol: Bad Format
// AllowDecimalPoint, AllowExponent: 122153
//
// Attempting to convert '1e03ff':
// None: Bad Format
// AllowLeadingWhite, AllowTrailingWhite: Bad Format
// Integer, AllowTrailingSign: Bad Format
// AllowThousands, AllowCurrencySymbol: Bad Format
// AllowDecimalPoint, AllowExponent: Bad Format
//
// Attempting to convert '91300.0e-2':
// None: Bad Format
// AllowLeadingWhite, AllowTrailingWhite: Bad Format
// Integer, AllowTrailingSign: Bad Format
// AllowThousands, AllowCurrencySymbol: Bad Format
// AllowDecimalPoint, AllowExponent: 913
Imports System.Globalization
Module Example
Public Sub Main()
Dim values() As String = { " 214309 ", "1,064,181", "(0)", "10241+", _
" + 21499 ", " +21499 ", "122153.00", _
"1e03ff", "91300.0e-2" }
Dim whitespace As NumberStyles = NumberStyles.AllowLeadingWhite Or NumberStyles.AllowTrailingWhite
Dim styles() As NumberStyles = { NumberStyles.None, _
whitespace, _
NumberStyles.AllowLeadingSign Or NumberStyles.AllowTrailingSign Or whitespace, _
NumberStyles.AllowThousands Or NumberStyles.AllowCurrencySymbol, _
NumberStyles.AllowExponent Or NumberStyles.AllowDecimalPoint }
' Attempt to convert each number using each style combination.
For Each value As String In values
Console.WriteLine("Attempting to convert '{0}':", value)
For Each style As NumberStyles In styles
Try
Dim number As ULong = UInt64.Parse(value, style)
Console.WriteLine(" {0}: {1}", style, number)
Catch e As FormatException
Console.WriteLine(" {0}: Bad Format", style)
Catch e As OverflowException
Console.WriteLine(" {0}: Overflow", value)
End Try
Next
Console.WriteLine()
Next
End Sub
End Module
' The example displays the following output:
' Attempting to convert ' 214309 ':
' None: Bad Format
' AllowLeadingWhite, AllowTrailingWhite: 214309
' Integer, AllowTrailingSign: 214309
' AllowThousands, AllowCurrencySymbol: Bad Format
' AllowDecimalPoint, AllowExponent: Bad Format
'
' Attempting to convert '1,064,181':
' None: Bad Format
' AllowLeadingWhite, AllowTrailingWhite: Bad Format
' Integer, AllowTrailingSign: Bad Format
' AllowThousands, AllowCurrencySymbol: 1064181
' AllowDecimalPoint, AllowExponent: Bad Format
'
' Attempting to convert '(0)':
' None: Bad Format
' AllowLeadingWhite, AllowTrailingWhite: Bad Format
' Integer, AllowTrailingSign: Bad Format
' AllowThousands, AllowCurrencySymbol: Bad Format
' AllowDecimalPoint, AllowExponent: Bad Format
'
' Attempting to convert '10241+':
' None: Bad Format
' AllowLeadingWhite, AllowTrailingWhite: Bad Format
' Integer, AllowTrailingSign: 10241
' AllowThousands, AllowCurrencySymbol: Bad Format
' AllowDecimalPoint, AllowExponent: Bad Format
'
' Attempting to convert ' + 21499 ':
' None: Bad Format
' AllowLeadingWhite, AllowTrailingWhite: Bad Format
' Integer, AllowTrailingSign: Bad Format
' AllowThousands, AllowCurrencySymbol: Bad Format
' AllowDecimalPoint, AllowExponent: Bad Format
'
' Attempting to convert ' +21499 ':
' None: Bad Format
' AllowLeadingWhite, AllowTrailingWhite: Bad Format
' Integer, AllowTrailingSign: 21499
' AllowThousands, AllowCurrencySymbol: Bad Format
' AllowDecimalPoint, AllowExponent: Bad Format
'
' Attempting to convert '122153.00':
' None: Bad Format
' AllowLeadingWhite, AllowTrailingWhite: Bad Format
' Integer, AllowTrailingSign: Bad Format
' AllowThousands, AllowCurrencySymbol: Bad Format
' AllowDecimalPoint, AllowExponent: 122153
'
' Attempting to convert '1e03ff':
' None: Bad Format
' AllowLeadingWhite, AllowTrailingWhite: Bad Format
' Integer, AllowTrailingSign: Bad Format
' AllowThousands, AllowCurrencySymbol: Bad Format
' AllowDecimalPoint, AllowExponent: Bad Format
'
' Attempting to convert '91300.0e-2':
' None: Bad Format
' AllowLeadingWhite, AllowTrailingWhite: Bad Format
' Integer, AllowTrailingSign: Bad Format
' AllowThousands, AllowCurrencySymbol: Bad Format
' AllowDecimalPoint, AllowExponent: 913
Opmerkingen
De style parameter definieert de stijlelementen (zoals witruimte, het positieve of negatieve tekensymbool, het teken voor het groepsscheidingsteken of het decimale puntsymbool) die zijn toegestaan in de s parameter om de parseringsbewerking te laten slagen.
style moet een combinatie zijn van bitvlagmen uit de NumberStyles opsomming. De style parameter maakt deze methode overbelast wanneer s de tekenreeksweergave van een hexadecimale waarde bevat, wanneer het getalsysteem (decimaal of hexadecimaal) dat wordt vertegenwoordigd s door alleen tijdens runtime bekend is, of wanneer u witruimte of een tekensymbool swilt weigeren.
Afhankelijk van de waarde van style, kan de s parameter de volgende elementen bevatten:
[ws][$][sign][digits,]digits[.fractional_digits][E[sign]exponential_digits][ws]
Elementen in vierkante haken ([ en ]) zijn optioneel. Indien style opgenomen NumberStyles.AllowHexSpecifier, kan de s parameter de volgende elementen bevatten:
[ws]hexdigits[ws]
In de volgende tabel wordt elk element beschreven.
| Element | Beschrijving |
|---|---|
| Ws | Optionele witruimte. Witruimte kan aan het begin van s de styleNumberStyles.AllowLeadingWhite vlag worden weergegeven en kan aan het einde van s de vlag worden weergegeven.styleNumberStyles.AllowTrailingWhite |
| $ | Een cultuurspecifiek valutasymbool. De positie in de tekenreeks wordt gedefinieerd door de NumberFormatInfo.CurrencyNegativePattern en NumberFormatInfo.CurrencyPositivePattern eigenschappen van de huidige cultuur. Het valutasymbool van de huidige cultuur kan worden weergegeven als sstyle deze de NumberStyles.AllowCurrencySymbol vlag bevat. |
| ondertekenen | Een optioneel teken. Het teken kan aan het begin van s de vlag worden weergegeven als style deze de NumberStyles.AllowLeadingSign vlag bevat en kan worden weergegeven aan het einde van s de vlag.styleNumberStyles.AllowTrailingSign Haakjes kunnen worden gebruikt s om een negatieve waarde aan te geven als style deze de NumberStyles.AllowParentheses vlag bevat. Het symbool voor een negatief teken kan echter alleen worden gebruikt met nul; anders gooit de methode een OverflowException. |
|
Cijfers fractional_digits exponential_digits |
Een reeks cijfers van 0 tot en met 9. Voor fractional_digits is alleen het cijfer 0 geldig. |
| , | Een cultuurspecifiek groepsscheidingsteken. Het groepsscheidingsteken van de huidige cultuur kan worden weergegeven als sstyle deze de NumberStyles.AllowThousands vlag bevat. |
| . | Een cultuurspecifiek decimaalteken. Het decimale puntsymbool van de huidige cultuur kan worden weergegeven s als style deze de NumberStyles.AllowDecimalPoint vlag bevat. Alleen het cijfer 0 kan worden weergegeven als een breukcijfer om de parseringsbewerking te laten slagen; als fractional_digits een ander cijfer bevat, wordt er een FormatException gegenereerd. |
| E | Het teken "e" of "E", dat aangeeft dat de waarde wordt weergegeven in exponentiële (wetenschappelijke) notatie. De s parameter kan een getal in exponentiële notatie vertegenwoordigen als style deze de NumberStyles.AllowExponent vlag bevat. |
| hexdigits | Een reeks hexadecimale cijfers van 0 tot en met f of 0 tot en met F. |
Note
Alle nultekens (U+0000) s worden genegeerd door de parseringsbewerking, ongeacht de waarde van het style argument.
Een tekenreeks met alleen cijfers (die overeenkomt met de NumberStyles.None stijl) parseert altijd goed als deze zich in het bereik van het UInt64 type bevindt. De meeste resterende NumberStyles leden bepalen elementen die mogelijk aanwezig zijn, maar die niet aanwezig zijn, in de invoertekenreeks. De volgende tabel geeft aan hoe afzonderlijke NumberStyles leden van invloed zijn op de elementen die aanwezig kunnen zijn in s.
NumberStyles Waarde |
Elementen die naast cijfers zijn toegestaan s |
|---|---|
| None | Alleen het cijferelement . |
| AllowDecimalPoint | De decimale puntelementen (.) en fractionele cijfers . |
| AllowExponent | Het teken "e" of "E", dat exponentiële notatie aangeeft, samen met exponential_digits. |
| AllowLeadingWhite | Het ws-element aan het begin van s. |
| AllowTrailingWhite | Het ws-element aan het einde van s. |
| AllowLeadingSign | Het tekenelement aan het begin van s. |
| AllowTrailingSign | Het tekenelement aan het einde van s. |
| AllowParentheses | Het tekenelement in de vorm van haakjes tussen de numerieke waarde. |
| AllowThousands | Het groepsscheidingsteken (,) element. |
| AllowCurrencySymbol | Het valutaelement ($). |
| Currency | Alle elementen.
s Kan echter geen hexadecimaal getal of een getal in exponentiële notatie vertegenwoordigen. |
| Float | Het ws-element aan het begin of einde van s, teken aan het begin van sen het decimaalteken (.). De s parameter kan ook exponentiële notatie gebruiken. |
| Number | De wselementen , signgroepsscheidingsteken (,) en decimaalteken (.). |
| Any | Alle elementen.
s Kan echter geen hexadecimaal getal vertegenwoordigen. |
In tegenstelling tot de andere NumberStyles waarden, die toestaan, maar niet vereisen, betekent de aanwezigheid van bepaalde stijlelementen in s, de NumberStyles.AllowHexSpecifier stijlwaarde dat de afzonderlijke numerieke tekens s altijd worden geïnterpreteerd als hexadecimale tekens. Geldige hexadecimale tekens zijn 0-9, A-F en a-f. Een voorvoegsel zoals '0x' wordt niet ondersteund en zorgt ervoor dat de parseringsbewerking mislukt. De enige andere vlaggen die kunnen worden gecombineerd met de style parameter zijn NumberStyles.AllowLeadingWhite en NumberStyles.AllowTrailingWhite. (De NumberStyles opsomming bevat een samengestelde getalstijl, NumberStyles.HexNumberdie beide spatievlagmen bevat.)
Note
Als s dit de tekenreeksweergave is van een hexadecimaal getal, kan het niet worden voorafgegaan door een decoratie (zoals 0x of &h) die deze onderscheidt als een hexadecimaal getal. Dit zorgt ervoor dat de conversie mislukt.
De s parameter wordt geparseerd met behulp van de opmaakgegevens in een NumberFormatInfo object dat is geïnitialiseerd voor de huidige systeemcultuur. Als u de cultuur wilt opgeven waarvan de opmaakgegevens worden gebruikt voor de parseringsbewerking, roept u de Parse(String, NumberStyles, IFormatProvider) overbelasting aan.