UInt64.Parse Yöntem
Tanım
Önemli
Bazı bilgiler ürünün ön sürümüyle ilgilidir ve sürüm öncesinde önemli değişiklikler yapılmış olabilir. Burada verilen bilgilerle ilgili olarak Microsoft açık veya zımni hiçbir garanti vermez.
Bir sayının dize gösterimini 64 bit işaretsiz tamsayı eşdeğerine dönüştürür.
Aşırı Yüklemeler
| Name | Description |
|---|---|
| Parse(String, NumberStyles, IFormatProvider) |
Belirtilen stilde ve kültüre özgü biçimdeki bir sayının dize gösterimini 64 bit işaretsiz tamsayı eşdeğerine dönüştürür. |
| Parse(ReadOnlySpan<Char>, NumberStyles, IFormatProvider) |
Bir sayının belirtilen stil ve kültüre özgü biçimdeki span gösterimini 64 bit işaretsiz tamsayı eşdeğerine dönüştürür. |
| Parse(ReadOnlySpan<Byte>, NumberStyles, IFormatProvider) |
UTF-8 karakterlik bir aralığı bir değere ayrıştırıyor. |
| Parse(String, IFormatProvider) |
Belirli bir kültüre özgü biçimdeki bir sayının dize gösterimini 64 bit işaretsiz tamsayı eşdeğerine dönüştürür. |
| Parse(ReadOnlySpan<Char>, IFormatProvider) |
Bir karakter aralığını bir değere ayrıştırıyor. |
| Parse(ReadOnlySpan<Byte>, IFormatProvider) |
UTF-8 karakterlik bir aralığı bir değere ayrıştırıyor. |
| Parse(String) |
Bir sayının dize gösterimini 64 bit işaretsiz tamsayı eşdeğerine dönüştürür. |
| Parse(String, NumberStyles) |
Belirtilen stildeki bir sayının dize gösterimini 64 bit işaretsiz tamsayı eşdeğerine dönüştürür. |
Parse(String, NumberStyles, IFormatProvider)
- Kaynak:
- UInt64.cs
- Kaynak:
- UInt64.cs
- Kaynak:
- UInt64.cs
- Kaynak:
- UInt64.cs
- Kaynak:
- UInt64.cs
Belirtilen stilde ve kültüre özgü biçimdeki bir sayının dize gösterimini 64 bit işaretsiz tamsayı eşdeğerine dönüştürür.
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
Parametreler
- s
- String
Dönüştürülecek sayıyı temsil eden dize. Dize, parametresi tarafından style belirtilen stil kullanılarak yorumlanır.
- style
- NumberStyles
içinde sbulunabilecek stil öğelerini gösteren sabit listesi değerlerinin bit düzeyinde birleşimi. Belirtilmesi gereken tipik bir değerdir Integer.
- provider
- IFormatProvider
hakkında skültüre özgü biçimlendirme bilgileri sağlayan bir nesne.
Döndürülenler
içinde belirtilen ssayıya eşdeğer 64 bit işaretsiz tamsayı.
Uygulamalar
- Öznitelikler
Özel durumlar
s parametresi null'dir.
style bir NumberStyles değer değildir.
-veya-
styleve HexNumber değerlerinin AllowHexSpecifier birleşimi değildir.
s parametresi ile styleuyumlu bir biçimde değil.
parametresi UInt64.MinValue değerinden küçük veya UInt64.MaxValue değerinden büyük bir sayıyı temsil eder.s
-veya-
s sıfır olmayan kesirli basamaklar içerir.
Örnekler
Aşağıdaki örnek, sayıların Parse(String, NumberStyles, IFormatProvider) çeşitli dize gösterimlerini 64 bit işaretsiz tamsayı değerlerine dönüştürmek için yöntemini kullanır.
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.
Açıklamalar
parametresi, style ayrıştırma işleminin başarılı olması için parametrede s izin verilen stil öğelerini (boşluk veya pozitif veya negatif işaret simgesi gibi) tanımlar. Numaralandırmadaki NumberStyles bit bayraklarının bir bileşimi olmalıdır.
değerine styles bağlı olarak parametresi aşağıdaki öğeleri içerebilir:
[ws][$][sign]digits[.fractional_digits][E[sign]exponential_digits][ws]
Köşeli ayraç ([ ve ]) içindeki öğeler isteğe bağlıdır. içeriyorsa styleNumberStyles.AllowHexSpecifiers, parametresi aşağıdaki öğeleri içerebilir:
[ws]hexdigits[ws]
Aşağıdaki tabloda her öğe açıklanmaktadır.
| Öğe | Açıklama |
|---|---|
| Ws | İsteğe bağlı boşluk. Boşluk bayrağını içeriyorsa başında s ve bayrağı içeriyorsa sonunda NumberStyles.AllowTrailingWhitesstyle görüntülenebilir.styleNumberStyles.AllowLeadingWhite |
| $ | Kültüre özgü para birimi simgesi. Dizedeki konumu, parametresinin yöntemi provider tarafından CurrencyPositivePattern döndürülen nesnesinin GetFormat özelliği NumberFormatInfo tarafından tanımlanır. Bayrağı içeriyorsa s para birimi simgesi içinde styleNumberStyles.AllowCurrencySymbol görüntülenebilir. |
| imza | İsteğe bağlı bir işaret. (yöntemi negatif bir işaret içeren bir OverflowException if s oluşturur ve sıfır olmayan bir sayıyı temsil eder.) İşaret, bayrağı içeriyorsa öğesinin sstyle başında görünebilir ve bayrağın dahil olup olmadığının sstyleNumberStyles.AllowTrailingSign sonunda görünebilir.NumberStyles.AllowLeadingSign Parantezler, bayrağı içeriyorsa s negatif bir değeri style belirtmek için içinde kullanılabilirNumberStyles.AllowParentheses. |
| Basamak | 0 ile 9 arasında bir basamak dizisi. |
| . | Kültüre özgü ondalık nokta simgesi. Bayrağı içeriyorsa geçerli kültürün s ondalık noktası simgesi içinde styleNumberStyles.AllowDecimalPoint görüntülenebilir. |
| fractional_digits | Bayrağı içeriyorsa NumberStyles.AllowExponent 0-9 style basamaklarının bir veya daha fazla tekrarı veya yoksa 0 rakamının bir veya daha fazla tekrarı. Kesirli basamaklar yalnızca s bayrağı içeriyorsa style içinde görüntülenebilirNumberStyles.AllowDecimalPoint. |
| E | Değerin üstel (bilimsel) gösterimde temsil olduğunu gösteren "e" veya "E" karakteri. parametresi, s bayrağını içeriyorsa üstel gösterimde style bir sayıyı NumberStyles.AllowExponent temsil edebilir. |
| exponential_digits | 0 ile 9 arasında bir basamak dizisi. parametresi, s bayrağını içeriyorsa üstel gösterimde style bir sayıyı NumberStyles.AllowExponent temsil edebilir. |
| hexdigits | 0'dan f'ye veya 0'dan F'ye kadar onaltılık basamak dizisi. |
Not
içindeki s sonlandırıcı NUL (U+0000) karakterleri, bağımsız değişkenin değerinden style bağımsız olarak ayrıştırma işlemi tarafından yoksayılır.
Yalnızca ondalık basamağı olan bir dize (stile NumberStyles.None karşılık gelir) her zaman başarıyla ayrıştırılıyor. Kalan NumberStyles üyelerin çoğu, bu giriş dizesinde mevcut olabilecek ancak mevcut olması gerekmeyen öğeleri denetler. Aşağıdaki tablo, tek tek NumberStyles üyelerin içinde sbulunabilecek öğeleri nasıl etkilediğini gösterir.
Bileşik NumberStyles olmayan değerler |
Basamaklara ek olarak izin verilen s öğeler |
|---|---|
| NumberStyles.None | Yalnızca ondalık basamaklar. |
| NumberStyles.AllowDecimalPoint | Ondalık nokta (.) ve fractional_digits öğeleri. Ancak, stil bayrağı içermiyorsa NumberStyles.AllowExponent, fractional_digits yalnızca bir veya daha fazla 0 basamak içermelidir; aksi takdirde, bir OverflowException oluşturulur. |
| NumberStyles.AllowExponent | Exponential_digits ile birlikte üstel gösterimi gösteren "e" veya "E" karakteri. |
| NumberStyles.AllowLeadingWhite | başındaki sws öğesi. |
| NumberStyles.AllowTrailingWhite | sonundaki s öğesi. |
| NumberStyles.AllowLeadingSign | Rakamlardan önceki bir işaret. |
| NumberStyles.AllowTrailingSign | Basamakların ardından gelen bir işaret. |
| NumberStyles.AllowParentheses | Negatif bir değeri belirtmek için basamaklardan önce ve sonra ayraçlar. |
| NumberStyles.AllowThousands | Grup ayırıcı (,) öğesi. |
| NumberStyles.AllowCurrencySymbol | Para birimi ($) öğesi. |
NumberStyles.AllowHexSpecifier Bayrağı kullanılıyorsa, s onaltılık bir değer olmalıdır. Geçerli onaltılık karakterler 0-9, A-F ve a-f şeklindedir. "0x" gibi bir ön ek desteklenmez ve ayrıştırma işleminin başarısız olmasına neden olur. Bununla birleştirilebilen diğer bayraklar yalnızca ve NumberStyles.AllowTrailingWhite'tirNumberStyles.AllowLeadingWhite. (Numaralandırma, NumberStylesNumberStyles.HexNumberher iki boşluk bayrağını da içeren bileşik bir sayı stili içerir.)
Not
s Parametre onaltılık bir sayının dize gösterimiyse, önünde onaltılık sayı olarak ayırt eden herhangi bir süsleme (veya &hgibi0x) bulunamaz. Bu, ayrıştırma işleminin bir özel durum oluşturmasına neden olur.
provider parametresi, yöntemi biçimi hakkında kültüre özgü bilgiler sağlayan bir nesne döndüren bir IFormatProviderNumberFormatInfo uygulamadır GetFormats. Ayrıştırma işlemine provider özel biçimlendirme bilgileri sağlamak için parametresini kullanmanın üç yolu vardır:
Biçimlendirme bilgileri sağlayan gerçek NumberFormatInfo nesneyi geçirebilirsiniz. (Uygulaması GetFormat yalnızca kendini döndürür.)
Biçimlendirmesi kullanılacak kültürü belirten bir CultureInfo nesne geçirebilirsiniz. Özelliği NumberFormat biçimlendirme bilgileri sağlar.
Özel IFormatProvider bir uygulama geçirebilirsiniz. GetFormat Yöntemi, biçimlendirme bilgileri sağlayan nesneyi örneklemeli ve döndürmelidirNumberFormatInfo.
ise providernull, NumberFormatInfo geçerli kültürün nesnesi kullanılır.
Ayrıca bkz.
Şunlara uygulanır
Parse(ReadOnlySpan<Char>, NumberStyles, IFormatProvider)
- Kaynak:
- UInt64.cs
- Kaynak:
- UInt64.cs
- Kaynak:
- UInt64.cs
- Kaynak:
- UInt64.cs
- Kaynak:
- UInt64.cs
Önemli
Bu API, CLS uyumlu değildir.
Bir sayının belirtilen stil ve kültüre özgü biçimdeki span gösterimini 64 bit işaretsiz tamsayı eşdeğerine dönüştürür.
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
Parametreler
- s
- ReadOnlySpan<Char>
Dönüştürülecek sayıyı temsil eden karakterleri içeren bir yayılma alanı. Span, parametresi tarafından style belirtilen stil kullanılarak yorumlanır.
- style
- NumberStyles
içinde sbulunabilecek stil öğelerini gösteren sabit listesi değerlerinin bit düzeyinde birleşimi. Belirtilmesi gereken tipik bir değerdir Integer.
- provider
- IFormatProvider
hakkında skültüre özgü biçimlendirme bilgileri sağlayan bir nesne.
Döndürülenler
içinde belirtilen ssayıya eşdeğer 64 bit işaretsiz tamsayı.
Uygulamalar
- Öznitelikler
Şunlara uygulanır
Parse(ReadOnlySpan<Byte>, NumberStyles, IFormatProvider)
- Kaynak:
- UInt64.cs
- Kaynak:
- UInt64.cs
- Kaynak:
- UInt64.cs
- Kaynak:
- UInt64.cs
UTF-8 karakterlik bir aralığı bir değere ayrıştırıyor.
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
Parametreler
- utf8Text
- ReadOnlySpan<Byte>
Ayrıştırılacak UTF-8 karakter aralığı.
- style
- NumberStyles
içinde utf8Textbulunabilecek sayı stillerinin bit düzeyinde birleşimi.
- provider
- IFormatProvider
hakkında utf8Textkültüre özgü biçimlendirme bilgileri sağlayan bir nesne.
Döndürülenler
ayrıştırma utf8Textişleminin sonucu.
Uygulamalar
Şunlara uygulanır
Parse(String, IFormatProvider)
- Kaynak:
- UInt64.cs
- Kaynak:
- UInt64.cs
- Kaynak:
- UInt64.cs
- Kaynak:
- UInt64.cs
- Kaynak:
- UInt64.cs
Belirli bir kültüre özgü biçimdeki bir sayının dize gösterimini 64 bit işaretsiz tamsayı eşdeğerine dönüştürür.
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
Parametreler
- s
- String
Dönüştürülecek sayıyı temsil eden dize.
- provider
- IFormatProvider
hakkında skültüre özgü biçimlendirme bilgileri sağlayan bir nesne.
Döndürülenler
içinde belirtilen ssayıya eşdeğer 64 bit işaretsiz tamsayı.
Uygulamalar
- Öznitelikler
Özel durumlar
s parametresi null'dir.
s parametresi doğru stilde değil.
parametresi UInt64.MinValue değerinden küçük veya UInt64.MaxValue değerinden büyük bir sayıyı temsil eder.s
Örnekler
Aşağıdaki örnek, web formunun düğme tıklama olay işleyicisidir. Kullanıcının yerel ayarını belirlemek için özelliği tarafından HttpRequest.UserLanguages döndürülen diziyi kullanır. Ardından bu yerel ayara karşılık gelen bir CultureInfo nesnenin örneğini oluşturur. Daha NumberFormatInfo sonra bu nesneye CultureInfo ait olan nesne, kullanıcının girişini bir UInt64 değere dönüştürmek için yöntemine geçirilirParse(String, IFormatProvider).
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
Açıklamalar
Yöntemin Parse(String, IFormatProvider) bu aşırı yüklemesi genellikle çeşitli yollarla biçimlendirilebilen metni bir UInt64 değere dönüştürmek için kullanılır. Örneğin, bir kullanıcı tarafından girilen metni HTML metin kutusuna sayısal bir değere dönüştürmek için kullanılabilir.
s parametresi formun bir sayısını içerir:
[ws] [sign]digits[ws]
Köşeli ayraç ([ ve ]) içindeki öğeler isteğe bağlıdır. Aşağıdaki tabloda her öğe açıklanmaktadır.
| Öğe | Açıklama |
|---|---|
| Ws | İsteğe bağlı boşluk. |
| imza | İsteğe bağlı pozitif işareti veya sıfır değerini temsil eden negatif bir işaret s . |
| Basamak | 0 ile 9 arasında bir basamak dizisi. |
s parametresi, stil kullanılarak NumberStyles.Integer yorumlanır. İşaretsiz tamsayı değerinin ondalık basamaklarına ek olarak, yalnızca baştaki ve sondaki boşluklara ve baştaki işarete izin verilir. (Negatif işaret varsa, s sıfır değerini temsil etmelidir veya yöntemi bir OverflowException.) stil öğelerini içinde bulunabilecek skültüre özgü biçimlendirme bilgileriyle birlikte açıkça tanımlamak için yöntemini kullanın Parse(String, NumberStyles, IFormatProvider) .
provider parametresi, yöntemi biçimi hakkında kültüre özgü bilgiler sağlayan bir nesne döndüren bir IFormatProviderNumberFormatInfo uygulamadır GetFormats. Ayrıştırma işlemine provider özel biçimlendirme bilgileri sağlamak için parametresini kullanmanın üç yolu vardır:
Biçimlendirme bilgileri sağlayan gerçek NumberFormatInfo nesneyi geçirebilirsiniz. (Uygulaması GetFormat yalnızca kendini döndürür.)
Biçimlendirmesi kullanılacak kültürü belirten bir CultureInfo nesne geçirebilirsiniz. Özelliği NumberFormat biçimlendirme bilgileri sağlar.
Özel IFormatProvider bir uygulama geçirebilirsiniz. GetFormat Yöntemi, biçimlendirme bilgileri sağlayan nesneyi örneklemeli ve döndürmelidirNumberFormatInfo.
ise providernull, NumberFormatInfo geçerli kültür için kullanılır.
Ayrıca bkz.
Şunlara uygulanır
Parse(ReadOnlySpan<Char>, IFormatProvider)
- Kaynak:
- UInt64.cs
- Kaynak:
- UInt64.cs
- Kaynak:
- UInt64.cs
- Kaynak:
- UInt64.cs
- Kaynak:
- UInt64.cs
Bir karakter aralığını bir değere ayrıştırıyor.
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
Parametreler
- s
- ReadOnlySpan<Char>
Ayrıştırılacak karakterlerin yayılma alanı.
- provider
- IFormatProvider
hakkında skültüre özgü biçimlendirme bilgileri sağlayan bir nesne.
Döndürülenler
ayrıştırma sişleminin sonucu.
Uygulamalar
Şunlara uygulanır
Parse(ReadOnlySpan<Byte>, IFormatProvider)
- Kaynak:
- UInt64.cs
- Kaynak:
- UInt64.cs
- Kaynak:
- UInt64.cs
- Kaynak:
- UInt64.cs
UTF-8 karakterlik bir aralığı bir değere ayrıştırıyor.
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
Parametreler
- utf8Text
- ReadOnlySpan<Byte>
Ayrıştırılacak UTF-8 karakter aralığı.
- provider
- IFormatProvider
hakkında utf8Textkültüre özgü biçimlendirme bilgileri sağlayan bir nesne.
Döndürülenler
ayrıştırma utf8Textişleminin sonucu.
Uygulamalar
Şunlara uygulanır
Parse(String)
- Kaynak:
- UInt64.cs
- Kaynak:
- UInt64.cs
- Kaynak:
- UInt64.cs
- Kaynak:
- UInt64.cs
- Kaynak:
- UInt64.cs
Bir sayının dize gösterimini 64 bit işaretsiz tamsayı eşdeğerine dönüştürür.
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
Parametreler
- s
- String
Dönüştürülecek sayıyı temsil eden dize.
Döndürülenler
içinde bulunan ssayıya eşdeğer 64 bit işaretsiz tamsayı.
- Öznitelikler
Özel durumlar
s parametresi null'dir.
s Parametresi doğru biçimde değil.
parametresi UInt64.MinValue değerinden küçük veya UInt64.MaxValue değerinden büyük bir sayıyı temsil eder.s
Örnekler
Aşağıdaki örnek, dize değerleri dizisini ayrıştırmak için yöntemini kullanır Parse .
string[] values = { "+13230", "-0", "1,390,146", "$190,235,421,127",
"0xFA1B", "163042", "-10", "14065839182",
"16e07", "134985.0", "-12034" };
foreach (string value in values)
{
try {
ulong number = UInt64.Parse(value);
Console.WriteLine("{0} --> {1}", value, number);
}
catch (FormatException) {
Console.WriteLine("{0}: Bad Format", value);
}
catch (OverflowException) {
Console.WriteLine("{0}: Overflow", value);
}
}
// The example displays the following output:
// +13230 --> 13230
// -0 --> 0
// 1,390,146: Bad Format
// $190,235,421,127: Bad Format
// 0xFA1B: Bad Format
// 163042 --> 163042
// -10: Overflow
// 14065839182 --> 14065839182
// 16e07: Bad Format
// 134985.0: Bad Format
// -12034: Overflow
let values =
[| "+13230"; "-0"; "1,390,146"; "$190,235,421,127"
"0xFA1B"; "163042"; "-10"; "14065839182"
"16e07"; "134985.0"; "-12034" |]
for value in values do
try
let number = UInt64.Parse value
printfn $"{value} --> {number}"
with
| :? FormatException ->
printfn $"{value}: Bad Format"
| :? OverflowException ->
printfn $"{value}: Overflow"
// The example displays the following output:
// +13230 --> 13230
// -0 --> 0
// 1,390,146: Bad Format
// $190,235,421,127: Bad Format
// 0xFA1B: Bad Format
// 163042 --> 163042
// -10: Overflow
// 14065839182 --> 14065839182
// 16e07: Bad Format
// 134985.0: Bad Format
// -12034: Overflow
Dim values() As String = { "+13230", "-0", "1,390,146", "$190,235,421,127", _
"0xFA1B", "163042", "-10", "14065839182", _
"16e07", "134985.0", "-12034" }
For Each value As String In values
Try
Dim number As ULong = UInt64.Parse(value)
Console.WriteLine("{0} --> {1}", value, number)
Catch e As FormatException
Console.WriteLine("{0}: Bad Format", value)
Catch e As OverflowException
Console.WriteLine("{0}: Overflow", value)
End Try
Next
' The example displays the following output:
' +13230 --> 13230
' -0 --> 0
' 1,390,146: Bad Format
' $190,235,421,127: Bad Format
' 0xFA1B: Bad Format
' 163042 --> 163042
' -10: Overflow
' 14065839182 --> 14065839182
' 16e07: Bad Format
' 134985.0: Bad Format
' -12034: Overflow
Açıklamalar
parametresi, s aşağıdaki biçimdeki bir sayının dize gösterimi olmalıdır.
[ws][sign]rakamlar[ws]
Köşeli ayraç ([ ve ]) içindeki öğeler isteğe bağlıdır. Aşağıdaki tabloda her öğe açıklanmaktadır.
| Öğe | Açıklama |
|---|---|
| Ws | İsteğe bağlı boşluk. |
| imza | İsteğe bağlı bir işaret. Geçerli işaret karakterleri geçerli kültürün NumberFormatInfo.NegativeSign ve NumberFormatInfo.PositiveSign özellikleri tarafından belirlenir. Ancak, negatif işaret simgesi yalnızca sıfır ile kullanılabilir; aksi takdirde, yöntemi bir OverflowExceptionoluşturur. |
| Basamak | 0 ile 9 arasında bir basamak dizisi. Baştaki sıfırlar yoksayılır. |
Not
parametresi tarafından s belirtilen dize, stil kullanılarak NumberStyles.Integer yorumlanır. Hiçbir grup ayırıcısı veya ondalık ayırıcı içeremez ve ondalık bölümü olamaz.
s parametresi, geçerli sistem kültürü için başlatılan bir System.Globalization.NumberFormatInfo nesnedeki biçimlendirme bilgileri kullanılarak ayrıştırılır. Daha fazla bilgi için bkz. NumberFormatInfo.CurrentInfo. Belirli bir kültürün biçimlendirme bilgilerini kullanarak bir dizeyi ayrıştırmak için yöntemini kullanın Parse(String, IFormatProvider) .
Ayrıca bkz.
Şunlara uygulanır
Parse(String, NumberStyles)
- Kaynak:
- UInt64.cs
- Kaynak:
- UInt64.cs
- Kaynak:
- UInt64.cs
- Kaynak:
- UInt64.cs
- Kaynak:
- UInt64.cs
Belirtilen stildeki bir sayının dize gösterimini 64 bit işaretsiz tamsayı eşdeğerine dönüştürür.
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
Parametreler
- s
- String
Dönüştürülecek sayıyı temsil eden dize. Dize, parametresi tarafından style belirtilen stil kullanılarak yorumlanır.
- style
- NumberStyles
İzin verilen biçimini belirten numaralandırma değerlerinin bit düzeyinde birleşimi s. Belirtilmesi gereken tipik bir değerdir Integer.
Döndürülenler
içinde belirtilen ssayıya eşdeğer 64 bit işaretsiz tamsayı.
- Öznitelikler
Özel durumlar
s parametresi null'dir.
style bir NumberStyles değer değildir.
-veya-
styleve HexNumber değerlerinin AllowHexSpecifier birleşimi değildir.
s parametresi ile styleuyumlu bir biçimde değil.
parametresi UInt64.MinValue değerinden küçük veya UInt64.MaxValue değerinden büyük bir sayıyı temsil eder.s
-veya-
s sıfır olmayan kesirli basamaklar içerir.
Örnekler
Aşağıdaki örnek, bir dizi NumberStyles değer kullanarak bir dize dizisindeki her öğeyi ayrıştırmaya çalışır.
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
Açıklamalar
style parametresi, ayrıştırma işleminin başarılı olması için parametrede s izin verilen stil öğelerini (boşluk, pozitif veya negatif işaret simgesi, grup ayırıcı simgesi veya ondalık ayırıcı simgesi gibi) tanımlar.
style sabit listesindeki bit bayraklarının NumberStyles birleşimi olmalıdır.
style parametresi, tarafından temsil s edilen sayı sistemi (ondalık veya onaltılık) yalnızca çalışma zamanında bilindiğinde veya içinde boşluk veya işaret simgesine izin vermek istemediğinizde, onaltılık değerin dize gösterimini içerdiğinde sbu yöntem aşırı yüklemesini kullanışlı s hale getirir.
değerine styles bağlı olarak parametresi aşağıdaki öğeleri içerebilir:
[ws][$][sign][digits,]digits[.fractional_digits][E[sign]exponential_digits][ws]
Köşeli ayraç ([ ve ]) içindeki öğeler isteğe bağlıdır. içeriyorsa styleNumberStyles.AllowHexSpecifiers, parametresi aşağıdaki öğeleri içerebilir:
[ws]hexdigits[ws]
Aşağıdaki tabloda her öğe açıklanmaktadır.
| Öğe | Açıklama |
|---|---|
| Ws | İsteğe bağlı boşluk. Bayrağı içeriyorsa başında boşluk görünebilir sstyle ve bayrağın dahil olup olmadığının NumberStyles.AllowLeadingWhitesstyle sonunda görüntülenebilir.NumberStyles.AllowTrailingWhite |
| $ | Kültüre özgü para birimi simgesi. Dizedeki konumu, geçerli kültürün NumberFormatInfo.CurrencyNegativePattern ve NumberFormatInfo.CurrencyPositivePattern özellikleri tarafından tanımlanır. Bayrağı içeriyorsa geçerli kültürün s para birimi simgesi içinde styleNumberStyles.AllowCurrencySymbol görüntülenebilir. |
| imza | İsteğe bağlı bir işaret. bayrağını içeriyorsas, işaretinin styleNumberStyles.AllowLeadingSign başında ve bayrağın dahil s olup olmadığının styleNumberStyles.AllowTrailingSign sonunda görüntülenebilir. Parantezler, bayrağı içeriyorsa s negatif bir değeri style belirtmek için içinde kullanılabilirNumberStyles.AllowParentheses. Ancak, negatif işaret simgesi yalnızca sıfır ile kullanılabilir; aksi takdirde, yöntemi bir OverflowExceptionoluşturur. |
|
Basamak fractional_digits exponential_digits |
0 ile 9 arasında bir basamak dizisi. fractional_digits için yalnızca 0 rakamı geçerlidir. |
| , | Kültüre özgü grup ayırıcı simgesi. Bayrağı içeriyorsa, geçerli kültürün grup ayırıcısı s içinde styleNumberStyles.AllowThousands görüntülenebilir. |
| . | Kültüre özgü ondalık nokta simgesi. Bayrağı içeriyorsa geçerli kültürün s ondalık noktası simgesi içinde styleNumberStyles.AllowDecimalPoint görüntülenebilir. Ayrıştırma işleminin başarılı olması için yalnızca 0 rakamı kesirli basamak olarak görünebilir; fractional_digits başka bir basamak içeriyorsa, bir FormatException oluşturulur. |
| E | Değerin üstel (bilimsel) gösterimde temsil olduğunu gösteren "e" veya "E" karakteri. parametresi, s bayrağını içeriyorsa üstel gösterimde style bir sayıyı NumberStyles.AllowExponent temsil edebilir. |
| hexdigits | 0'dan f'ye veya 0'dan F'ye kadar onaltılık basamak dizisi. |
Not
içindeki s sonlandırıcı NUL (U+0000) karakterleri, bağımsız değişkenin değerinden style bağımsız olarak ayrıştırma işlemi tarafından yoksayılır.
Yalnızca basamak içeren bir dize (stile NumberStyles.None karşılık gelir) türün aralığındaysa UInt64 her zaman başarıyla ayrıştırılır. Geri kalan NumberStyles üyelerin çoğu, giriş dizesinde mevcut olabilecek ancak mevcut olması gerekmeyen öğeleri denetler. Aşağıdaki tablo, tek tek NumberStyles üyelerin içinde sbulunabilecek öğeleri nasıl etkilediğini gösterir.
NumberStyles değer |
Basamaklara ek olarak izin verilen s öğeler |
|---|---|
| None | Yalnızca rakamlar öğesi. |
| AllowDecimalPoint | Ondalık nokta (.) ve kesirli basamak öğeleri. |
| AllowExponent | Exponential_digits ile birlikte üstel gösterimi gösteren "e" veya "E" karakteri. |
| AllowLeadingWhite | başındaki s öğesi. |
| AllowTrailingWhite | sonundaki s öğesi. |
| AllowLeadingSign | başındaki s öğesi. |
| AllowTrailingSign | sonundaki s öğesi. |
| AllowParentheses | Sayısal değeri kapsayan parantez biçimindeki sign öğesi. |
| AllowThousands | Grup ayırıcı (,) öğesi. |
| AllowCurrencySymbol | Para birimi ($) öğesi. |
| Currency | Tüm öğeler. Ancak, s üstel gösterimde onaltılık bir sayıyı veya sayıyı temsil edemez. |
| Float | başında veya sonundaki s öğesi, öğesinin başında ve ondalık nokta (s) simgesiyle işaret eder. parametresi üstel s gösterim de kullanabilir. |
| Number | , , grup ayırıcısı (ws) ve ondalık ayırıcı (sign) öğeleri. |
| Any | Tüm öğeler. Ancak, s onaltılık bir sayıyı temsil edemez. |
içinde belirli stil öğelerinin NumberStylessbulunmasına izin veren ancak gerektirmeyen diğer NumberStyles.AllowHexSpecifier değerlerden farklı olarak, stil değeri içindeki tek tek sayısal karakterlerin s her zaman onaltılık karakterler olarak yorumlandığı anlamına gelir. Geçerli onaltılık karakterler 0-9, A-F ve a-f şeklindedir. "0x" gibi bir ön ek desteklenmez ve ayrıştırma işleminin başarısız olmasına neden olur. parametresiyle style birleştirilebilen diğer bayraklar yalnızca ve NumberStyles.AllowLeadingWhite'tirNumberStyles.AllowTrailingWhite. (Numaralandırma, NumberStylesNumberStyles.HexNumberher iki boşluk bayrağını da içeren bileşik bir sayı stili içerir.)
Not
Onaltılık bir sayının dize gösterimi ises, bundan önce onu onaltılık sayı olarak ayıran herhangi bir süsleme (veya 0xgibi&h) olamaz. Bu, dönüştürmenin başarısız olmasına neden olur.
s parametresi, geçerli sistem kültürü için başlatılan bir NumberFormatInfo nesnedeki biçimlendirme bilgileri kullanılarak ayrıştırılır. Ayrıştırma işlemi için biçimlendirme bilgileri kullanılan kültürü belirtmek için aşırı yüklemeyi çağırın Parse(String, NumberStyles, IFormatProvider) .