UInt32.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 32 bit işaretsiz tamsayı eşdeğerine dönüştürür.
Aşırı Yüklemeler
Parse(String, NumberStyles, IFormatProvider) |
Belirtilen stil ve kültüre özgü biçimdeki bir sayının dize gösterimini 32 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 32 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) |
Belirtilen kültüre özgü biçimdeki bir sayının dize gösterimini 32 bit işaretsiz tamsayı eşdeğerine dönüştürür. |
Parse(String, NumberStyles) |
Belirtilen stildeki bir sayının dize gösterimini 32 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 32 bit işaretsiz tamsayı eşdeğerine dönüştürür. |
Parse(String, NumberStyles, IFormatProvider)
- Kaynak:
- UInt32.cs
- Kaynak:
- UInt32.cs
- Kaynak:
- UInt32.cs
Belirtilen stilde ve kültüre özgü biçimdeki bir sayının dize gösterimini, 32 bit işaretsiz tamsayı eşdeğerine dönüştürür.
public:
static System::UInt32 Parse(System::String ^ s, System::Globalization::NumberStyles style, IFormatProvider ^ provider);
public:
static System::UInt32 Parse(System::String ^ s, System::Globalization::NumberStyles style, IFormatProvider ^ provider) = System::Numerics::INumberBase<System::UInt32>::Parse;
[System.CLSCompliant(false)]
public static uint Parse (string s, System.Globalization.NumberStyles style, IFormatProvider provider);
public static uint Parse (string s, System.Globalization.NumberStyles style, IFormatProvider? provider);
[System.CLSCompliant(false)]
public static uint Parse (string s, System.Globalization.NumberStyles style, IFormatProvider? provider);
[<System.CLSCompliant(false)>]
static member Parse : string * System.Globalization.NumberStyles * IFormatProvider -> uint32
static member Parse : string * System.Globalization.NumberStyles * IFormatProvider -> uint32
Public Shared Function Parse (s As String, style As NumberStyles, provider As IFormatProvider) As UInteger
Parametreler
- s
- String
Dönüştürülecek sayıyı temsil eden bir dize. Dize, parametresi tarafından style
belirtilen stil kullanılarak yorumlanır.
- style
- NumberStyles
içinde bulunabilecek s
stil öğelerini gösteren sabit listesi değerlerinin bit düzeyinde birleşimi. Belirtilmesi gereken tipik bir değerdir Integer.
- provider
- IFormatProvider
hakkında s
kültüre özgü biçimlendirme bilgileri sağlayan bir nesne.
Döndürülenler
içinde s
belirtilen sayıya eşdeğer 32 bit işaretsiz tamsayı.
Uygulamalar
- Öznitelikler
Özel durumlar
s
, null
değeridir.
style
bir NumberStyles değer değildir.
-veya-
style
ve HexNumber değerlerinin AllowHexSpecifier birleşimi değildir.
s
ile style
uyumlu bir biçimde değil.
s
UInt32.MinValue değerinden küçük veya UInt32.MaxValue değerinden büyük bir sayıyı temsil eder.
-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 32 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,
UInt32.Parse(value, style, ci));
}
catch (FormatException) {
Console.WriteLine(" Unable to parse '{0}'.", value);
}
catch (OverflowException) {
Console.WriteLine(" '{0}' is out of range of the UInt32 type.",
value);
}
}
}
}
}
}
// The example displays the following output:
// Parsing strings using the English (United States) culture
// Style: Integer
// Converted '170209' to 170209.
// Unable to parse '+170209.0'.
// Unable to parse '+170209,0'.
// Unable to parse '-103214.00'.
// Unable to parse '-103214,00'.
// Unable to parse '104561.1'.
// Unable to parse '104561,1'.
// Style: Integer, AllowDecimalPoint
// Converted '170209' to 170209.
// Converted '+170209.0' to 170209.
// Unable to parse '+170209,0'.
// '-103214.00' is out of range of the UInt32 type.
// Unable to parse '-103214,00'.
// '104561.1' is out of range of the UInt32 type.
// Unable to parse '104561,1'.
// Parsing strings using the French (France) culture
// Style: Integer
// Converted '170209' to 170209.
// Unable to parse '+170209.0'.
// Unable to parse '+170209,0'.
// Unable to parse '-103214.00'.
// Unable to parse '-103214,00'.
// Unable to parse '104561.1'.
// Unable to parse '104561,1'.
// Style: Integer, AllowDecimalPoint
// Converted '170209' to 170209.
// Unable to parse '+170209.0'.
// Converted '+170209,0' to 170209.
// Unable to parse '-103214.00'.
// '-103214,00' is out of range of the UInt32 type.
// Unable to parse '104561.1'.
// '104561,1' is out of range of the UInt32 type.
open System
open System.Globalization
let cultureNames = [| "en-US"; "fr-FR" |]
let styles =
[| NumberStyles.Integer; NumberStyles.Integer ||| NumberStyles.AllowDecimalPoint |]
let values =
[| "170209"; "+170209.0"; "+170209,0"; "-103214.00"; "-103214,00"; "104561.1"; "104561,1" |]
// Parse strings using each culture
for cultureName in cultureNames do
let ci = CultureInfo cultureName
printfn $"Parsing strings using the {ci.DisplayName} culture"
// Use each style.
for style in styles do
printfn $" Style: {style}"
// Parse each numeric string.
for value in values do
try
printfn $" Converted '{value}' to {UInt32.Parse(value, style, ci)}."
with
| :? FormatException ->
printfn $" Unable to parse '{value}'."
| :? OverflowException ->
printfn $" '{value}' is out of range of the UInt32 type."
// The example displays the following output:
// Parsing strings using the English (United States) culture
// Style: Integer
// Converted '170209' to 170209.
// Unable to parse '+170209.0'.
// Unable to parse '+170209,0'.
// Unable to parse '-103214.00'.
// Unable to parse '-103214,00'.
// Unable to parse '104561.1'.
// Unable to parse '104561,1'.
// Style: Integer, AllowDecimalPoint
// Converted '170209' to 170209.
// Converted '+170209.0' to 170209.
// Unable to parse '+170209,0'.
// '-103214.00' is out of range of the UInt32 type.
// Unable to parse '-103214,00'.
// '104561.1' is out of range of the UInt32 type.
// Unable to parse '104561,1'.
// Parsing strings using the French (France) culture
// Style: Integer
// Converted '170209' to 170209.
// Unable to parse '+170209.0'.
// Unable to parse '+170209,0'.
// Unable to parse '-103214.00'.
// Unable to parse '-103214,00'.
// Unable to parse '104561.1'.
// Unable to parse '104561,1'.
// Style: Integer, AllowDecimalPoint
// Converted '170209' to 170209.
// Unable to parse '+170209.0'.
// Converted '+170209,0' to 170209.
// Unable to parse '-103214.00'.
// '-103214,00' is out of range of the UInt32 type.
// Unable to parse '104561.1'.
// '104561,1' is out of range of the UInt32 type.
Imports System.Globalization
Module Example
Public Sub Main()
Dim cultureNames() As String = { "en-US", "fr-FR" }
Dim styles() As NumberStyles = { NumberStyles.Integer, _
NumberStyles.Integer Or NumberStyles.AllowDecimalPoint }
Dim values() As String = { "170209", "+170209.0", "+170209,0", "-103214.00", _
"-103214,00", "104561.1", "104561,1" }
' Parse strings using each culture
For Each cultureName As String In cultureNames
Dim ci As New CultureInfo(cultureName)
Console.WriteLine("Parsing strings using the {0} culture", ci.DisplayName)
' Use each style.
For Each style As NumberStyles In styles
Console.WriteLine(" Style: {0}", style.ToString())
' Parse each numeric string.
For Each value As String In values
Try
Console.WriteLine(" Converted '{0}' to {1}.", value, _
UInt32.Parse(value, style, ci))
Catch e As FormatException
Console.WriteLine(" Unable to parse '{0}'.", value)
Catch e As OverflowException
Console.WriteLine(" '{0}' is out of range of the UInt32 type.", _
value)
End Try
Next
Next
Next
End Sub
End Module
' The example displays the following output:
' Parsing strings using the English (United States) culture
' Style: Integer
' Converted '170209' to 170209.
' Unable to parse '+170209.0'.
' Unable to parse '+170209,0'.
' Unable to parse '-103214.00'.
' Unable to parse '-103214,00'.
' Unable to parse '104561.1'.
' Unable to parse '104561,1'.
' Style: Integer, AllowDecimalPoint
' Converted '170209' to 170209.
' Converted '+170209.0' to 170209.
' Unable to parse '+170209,0'.
' '-103214.00' is out of range of the UInt32 type.
' Unable to parse '-103214,00'.
' '104561.1' is out of range of the UInt32 type.
' Unable to parse '104561,1'.
' Parsing strings using the French (France) culture
' Style: Integer
' Converted '170209' to 170209.
' Unable to parse '+170209.0'.
' Unable to parse '+170209,0'.
' Unable to parse '-103214.00'.
' Unable to parse '-103214,00'.
' Unable to parse '104561.1'.
' Unable to parse '104561,1'.
' Style: Integer, AllowDecimalPoint
' Converted '170209' to 170209.
' Unable to parse '+170209.0'.
' Converted '+170209,0' to 170209.
' Unable to parse '-103214.00'.
' '-103214,00' is out of range of the UInt32 type.
' Unable to parse '104561.1'.
' '104561,1' is out of range of the UInt32 type.
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. Sabit listesindeki bit bayraklarının NumberStyles bir bileşimi olmalıdır.
değerine style
s
bağlı olarak parametresi aşağıdaki öğeleri içerebilir:
[ws] [$][sign]digits[.fractional_digits][E[sign]exponential_digits][ws]
Köşeli ayraçlar ([ve]) içindeki öğeler isteğe bağlıdır. içeriyorsa style
NumberStyles.AllowHexSpecifiers
, parametresi aşağıdaki öğeleri içerebilir:
[ws] hexdigits[ws]
Aşağıdaki tablo her öğeyi açıklar.
Öğe | Açıklama |
---|---|
Ws | İsteğe bağlı beyaz boşluk. Bayrağı içeriyorsa boşluk başında s style ve bayrağı içeriyorsa sonunda s style NumberStyles.AllowTrailingWhite görüntülenebilir.NumberStyles.AllowLeadingWhite |
$ | Kültüre özgü para birimi simgesi. Dizedeki konumu, parametresinin yöntemi provider tarafından CurrencyPositivePattern döndürülen nesnenin özelliği NumberFormatInfo tarafından GetFormat tanımlanır. Bayrağı içeriyorsa NumberStyles.AllowCurrencySymbol para birimi simgesi içinde s style görünebilir. |
sign | İsteğe bağlı bir işaret. (yöntemi negatif bir işaret içeriyorsa bir OverflowExceptions oluşturur ve sıfır olmayan bir sayıyı temsil eder.) işareti bayrağını içeriyorsa başında s style ve bayrağını içeriyorsa NumberStyles.AllowLeadingSignNumberStyles.AllowTrailingSign sonunu s style görüntüleyebilir. Parantezler, bayrağı içeriyorsa NumberStyles.AllowParentheses negatif bir değeri style belirtmek için içinde kullanılabilirs . |
Basamak | 0 İle 9 arasında bir basamak dizisi. |
. | Bir kültüre özgü ondalık nokta sembolü. Bayrağı içeriyorsa geçerli kültürün NumberStyles.AllowDecimalPoint ondalık noktası simgesi içinde s style görünebilir. |
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 style bayrağı içeriyorsa NumberStyles.AllowDecimalPoint içinde görüntülenebilirs . |
E | Değerin üslü (bilimsel) gösterimle temsil edildiğini gösteren "e" veya "E" karakteri. parametresi, s bayrağını içeriyorsa bir sayıyı üstel gösteriminde style NumberStyles.AllowExponent gösterebilir. |
exponential_digits | 0 İle 9 arasında bir basamak dizisi. parametresi, s bayrağını içeriyorsa bir sayıyı üstel gösteriminde style NumberStyles.AllowExponent gösterebilir. |
hexdigits | 0 İle f veya 0 ile f arasında 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 tabloda, tek tek NumberStyles üyelerin içinde s
bulunabilecek öğeleri nasıl etkilediği gösterilir.
Bileşik NumberStyles olmayan değerler |
Basamaklara ek olarak izin verilen s öğeler |
---|---|
NumberStyles.None | Yalnızca ondalık basamaklar. |
NumberStyles.AllowDecimalPoint | Ondalık ayırıcı (.) 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 s ws öğesi. |
NumberStyles.AllowTrailingWhite | sonundaki s ws öğ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ısı (,) öğesi. |
NumberStyles.AllowCurrencySymbol | Para birimi ($) öğesi. |
NumberStyles.AllowHexSpecifier Bayrağı kullanılıyorsa, s
onaltılık bir değer olmalıdır. 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 &h
gibi0x
) olamaz. 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 nesnesi 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 basitçe kendisini 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 provider
null
, NumberFormatInfo geçerli kültürün nesnesi kullanılır.
Ayrıca bkz.
Şunlara uygulanır
Parse(ReadOnlySpan<Char>, NumberStyles, IFormatProvider)
- Kaynak:
- UInt32.cs
- Kaynak:
- UInt32.cs
- Kaynak:
- UInt32.cs
Önemli
Bu API, CLS uyumlu değildir.
Bir sayının belirtilen stil ve kültüre özgü biçimdeki span gösterimini 32 bit işaretsiz tamsayı eşdeğerine dönüştürür.
public static uint Parse (ReadOnlySpan<char> s, System.Globalization.NumberStyles style = System.Globalization.NumberStyles.Integer, IFormatProvider? provider = default);
[System.CLSCompliant(false)]
public static uint Parse (ReadOnlySpan<char> s, System.Globalization.NumberStyles style = System.Globalization.NumberStyles.Integer, IFormatProvider provider = default);
[System.CLSCompliant(false)]
public static uint Parse (ReadOnlySpan<char> s, System.Globalization.NumberStyles style = System.Globalization.NumberStyles.Integer, IFormatProvider? provider = default);
static member Parse : ReadOnlySpan<char> * System.Globalization.NumberStyles * IFormatProvider -> uint32
[<System.CLSCompliant(false)>]
static member Parse : ReadOnlySpan<char> * System.Globalization.NumberStyles * IFormatProvider -> uint32
Public Shared Function Parse (s As ReadOnlySpan(Of Char), Optional style As NumberStyles = System.Globalization.NumberStyles.Integer, Optional provider As IFormatProvider = Nothing) As UInteger
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 bulunabilecek s
stil öğelerini gösteren sabit listesi değerlerinin bit düzeyinde birleşimi. Belirtilmesi gereken tipik bir değerdir Integer.
- provider
- IFormatProvider
hakkında s
kültüre özgü biçimlendirme bilgileri sağlayan bir nesne.
Döndürülenler
içinde s
belirtilen sayıya eşdeğer 32 bit işaretsiz tamsayı.
Uygulamalar
- Öznitelikler
Şunlara uygulanır
Parse(ReadOnlySpan<Byte>, NumberStyles, IFormatProvider)
- Kaynak:
- UInt32.cs
- Kaynak:
- UInt32.cs
UTF-8 karakterlik bir aralığı bir değere ayrıştırıyor.
public static uint Parse (ReadOnlySpan<byte> utf8Text, System.Globalization.NumberStyles style = System.Globalization.NumberStyles.Integer, IFormatProvider? provider = default);
static member Parse : ReadOnlySpan<byte> * System.Globalization.NumberStyles * IFormatProvider -> uint32
Public Shared Function Parse (utf8Text As ReadOnlySpan(Of Byte), Optional style As NumberStyles = System.Globalization.NumberStyles.Integer, Optional provider As IFormatProvider = Nothing) As UInteger
Parametreler
- utf8Text
- ReadOnlySpan<Byte>
Ayrıştırılacak UTF-8 karakter aralığı.
- style
- NumberStyles
içinde utf8Text
bulunabilecek sayı stillerinin bit düzeyinde birleşimi.
- provider
- IFormatProvider
hakkında utf8Text
kültüre özgü biçimlendirme bilgileri sağlayan bir nesne.
Döndürülenler
ayrıştırma utf8Text
sonucu.
Uygulamalar
Şunlara uygulanır
Parse(String, IFormatProvider)
- Kaynak:
- UInt32.cs
- Kaynak:
- UInt32.cs
- Kaynak:
- UInt32.cs
Belirtilen kültüre özgü biçimdeki bir sayının dize gösterimini 32 bit işaretsiz tamsayı eşdeğerine dönüştürür.
public:
static System::UInt32 Parse(System::String ^ s, IFormatProvider ^ provider);
public:
static System::UInt32 Parse(System::String ^ s, IFormatProvider ^ provider) = IParsable<System::UInt32>::Parse;
[System.CLSCompliant(false)]
public static uint Parse (string s, IFormatProvider provider);
public static uint Parse (string s, IFormatProvider? provider);
[System.CLSCompliant(false)]
public static uint Parse (string s, IFormatProvider? provider);
[<System.CLSCompliant(false)>]
static member Parse : string * IFormatProvider -> uint32
static member Parse : string * IFormatProvider -> uint32
Public Shared Function Parse (s As String, provider As IFormatProvider) As UInteger
Parametreler
- s
- String
Dönüştürülecek sayıyı temsil eden bir dize.
- provider
- IFormatProvider
hakkında s
kültüre özgü biçimlendirme bilgileri sağlayan bir nesne.
Döndürülenler
içinde s
belirtilen sayıya eşdeğer 32 bit işaretsiz tamsayı.
Uygulamalar
- Öznitelikler
Özel durumlar
s
, null
değeridir.
s
doğru stilde değil.
s
UInt32.MinValue değerinden küçük veya UInt32.MaxValue değerinden büyük bir sayıyı temsil eder.
Örnekler
Aşağıdaki örnek, bir Web formunun düğme tıklamalı 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. Bu NumberFormatInfo nesneye CultureInfo ait olan nesne daha sonra kullanıcının girişini bir UInt32 değere Parse(String, IFormatProvider) dönüştürmek için yöntemine geçirilir.
protected void OkToUInteger_Click(object sender, EventArgs e)
{
string locale;
uint number;
CultureInfo culture;
// Return if string is empty
if (String.IsNullOrEmpty(this.inputNumber.Text))
return;
// Get locale of web request to determine possible format of number
if (Request.UserLanguages.Length == 0)
return;
locale = Request.UserLanguages[0];
if (String.IsNullOrEmpty(locale))
return;
// Instantiate CultureInfo object for the user's locale
culture = new CultureInfo(locale);
// Convert user input from a string to a number
try
{
number = UInt32.Parse(this.inputNumber.Text, culture.NumberFormat);
}
catch (FormatException)
{
return;
}
catch (Exception)
{
return;
}
// Output number to label on web form
this.outputNumber.Text = "Number is " + number.ToString();
}
Protected Sub OKToUInteger_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles OKToUInteger.Click
Dim locale As String
Dim culture As CultureInfo
Dim number As UInteger
' Return if string is empty
If String.IsNullOrEmpty(Me.inputNumber.Text) Then Exit Sub
' Get locale of web request to determine possible format of number
If Request.UserLanguages.Length = 0 Then Exit Sub
locale = Request.UserLanguages(0)
If String.IsNullOrEmpty(locale) Then Exit Sub
' Instantiate CultureInfo object for the user's locale
culture = New CultureInfo(locale)
' Convert user input from a string to a number
Try
number = UInt32.Parse(Me.inputNumber.Text, culture.NumberFormat)
Catch ex As FormatException
Exit Sub
Catch ex As Exception
Exit Sub
End Try
' Output number to label on web form
Me.outputNumber.Text = "Number is " & number.ToString()
End Sub
Açıklamalar
s
parametresi formun bir sayısını içerir:
[ws] [sign] rakamlar[ws]
Köşeli ayraçlar ([ve]) içindeki öğeler isteğe bağlıdır. Aşağıdaki tablo her öğeyi açıklar.
Öğe | Açıklama |
---|---|
Ws | İsteğe bağlı beyaz boşluk. |
sign | İsteğe bağlı bir işaret veya sıfır değerini temsil eden s negatif bir işaret. |
Basamak | 0 İle 9 arasında değişen 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şareti varsa, s
sıfır değerini temsil etmelidir veya yöntemi bir OverflowExceptionoluşturur.) stil öğelerini içinde bulunabilecek s
kü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 nesnesi 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 basitçe 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 provider
null
, NumberFormatInfo geçerli kültür için kullanılır.
Ayrıca bkz.
Şunlara uygulanır
Parse(String, NumberStyles)
- Kaynak:
- UInt32.cs
- Kaynak:
- UInt32.cs
- Kaynak:
- UInt32.cs
Belirtilen stildeki bir sayının dize gösterimini 32 bit işaretsiz tamsayı eşdeğerine dönüştürür.
public:
static System::UInt32 Parse(System::String ^ s, System::Globalization::NumberStyles style);
[System.CLSCompliant(false)]
public static uint Parse (string s, System.Globalization.NumberStyles style);
public static uint Parse (string s, System.Globalization.NumberStyles style);
[<System.CLSCompliant(false)>]
static member Parse : string * System.Globalization.NumberStyles -> uint32
static member Parse : string * System.Globalization.NumberStyles -> uint32
Public Shared Function Parse (s As String, style As NumberStyles) As UInteger
Parametreler
- s
- String
Dönüştürülecek sayıyı temsil eden bir 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 s
belirtilen sayıya eşdeğer 32 bit işaretsiz tamsayı.
- Öznitelikler
Özel durumlar
s
, null
değeridir.
style
bir NumberStyles değer değildir.
-veya-
style
ve HexNumber değerlerinin AllowHexSpecifier birleşimi değildir.
s
ile style
uyumlu bir biçimde değil.
s
UInt32.MinValue değerinden küçük veya UInt32.MaxValue değerinden büyük bir sayıyı temsil eder.
-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 {
uint number = UInt32.Parse(value, style);
Console.WriteLine(" {0}: {1}", style, number);
}
catch (FormatException) {
Console.WriteLine(" {0}: Bad Format", style);
}
catch (OverflowException)
{
Console.WriteLine(" {0}: Overflow", value);
}
}
Console.WriteLine();
}
}
}
// The example displays the following output:
// Attempting to convert ' 214309 ':
// None: Bad Format
// AllowLeadingWhite, AllowTrailingWhite: 214309
// Integer, AllowTrailingSign: 214309
// AllowThousands, AllowCurrencySymbol: Bad Format
// AllowDecimalPoint, AllowExponent: Bad Format
//
// Attempting to convert '1,064,181':
// None: Bad Format
// AllowLeadingWhite, AllowTrailingWhite: Bad Format
// Integer, AllowTrailingSign: Bad Format
// AllowThousands, AllowCurrencySymbol: 1064181
// AllowDecimalPoint, AllowExponent: Bad Format
//
// Attempting to convert '(0)':
// None: Bad Format
// AllowLeadingWhite, AllowTrailingWhite: Bad Format
// Integer, AllowTrailingSign: Bad Format
// AllowThousands, AllowCurrencySymbol: Bad Format
// AllowDecimalPoint, AllowExponent: Bad Format
//
// Attempting to convert '10241+':
// None: Bad Format
// AllowLeadingWhite, AllowTrailingWhite: Bad Format
// Integer, AllowTrailingSign: 10241
// AllowThousands, AllowCurrencySymbol: Bad Format
// AllowDecimalPoint, AllowExponent: Bad Format
//
// Attempting to convert ' + 21499 ':
// None: Bad Format
// AllowLeadingWhite, AllowTrailingWhite: Bad Format
// Integer, AllowTrailingSign: Bad Format
// AllowThousands, AllowCurrencySymbol: Bad Format
// AllowDecimalPoint, AllowExponent: Bad Format
//
// Attempting to convert ' +21499 ':
// None: Bad Format
// AllowLeadingWhite, AllowTrailingWhite: Bad Format
// Integer, AllowTrailingSign: 21499
// AllowThousands, AllowCurrencySymbol: Bad Format
// AllowDecimalPoint, AllowExponent: Bad Format
//
// Attempting to convert '122153.00':
// None: Bad Format
// AllowLeadingWhite, AllowTrailingWhite: Bad Format
// Integer, AllowTrailingSign: Bad Format
// AllowThousands, AllowCurrencySymbol: Bad Format
// AllowDecimalPoint, AllowExponent: 122153
//
// Attempting to convert '1e03ff':
// None: Bad Format
// AllowLeadingWhite, AllowTrailingWhite: Bad Format
// Integer, AllowTrailingSign: Bad Format
// AllowThousands, AllowCurrencySymbol: Bad Format
// AllowDecimalPoint, AllowExponent: Bad Format
//
// Attempting to convert '91300.0e-2':
// None: Bad Format
// AllowLeadingWhite, AllowTrailingWhite: Bad Format
// Integer, AllowTrailingSign: Bad Format
// AllowThousands, AllowCurrencySymbol: Bad Format
// AllowDecimalPoint, AllowExponent: 913
open System
open System.Globalization
let values =
[| " 214309 "; "1,064,181"; "(0)"; "10241+"; " + 21499 "
" +21499 "; "122153.00"; "1e03ff"; "91300.0e-2" |]
let whitespace = NumberStyles.AllowLeadingWhite ||| NumberStyles.AllowTrailingWhite
let styles =
[| NumberStyles.None; whitespace
NumberStyles.AllowLeadingSign ||| NumberStyles.AllowTrailingSign ||| whitespace
NumberStyles.AllowThousands ||| NumberStyles.AllowCurrencySymbol
NumberStyles.AllowExponent ||| NumberStyles.AllowDecimalPoint |]
// Attempt to convert each number using each style combination.
for value in values do
printfn $"Attempting to convert '{value}':"
for style in styles do
try
let number = UInt32.Parse(value, style)
printfn $" {style}: {number}"
with
| :? FormatException ->
printfn $" {style}: Bad Format"
| :? OverflowException ->
printfn $" {value}: Overflow"
printfn ""
// The example displays the following output:
// Attempting to convert ' 214309 ':
// None: Bad Format
// AllowLeadingWhite, AllowTrailingWhite: 214309
// Integer, AllowTrailingSign: 214309
// AllowThousands, AllowCurrencySymbol: Bad Format
// AllowDecimalPoint, AllowExponent: Bad Format
//
// Attempting to convert '1,064,181':
// None: Bad Format
// AllowLeadingWhite, AllowTrailingWhite: Bad Format
// Integer, AllowTrailingSign: Bad Format
// AllowThousands, AllowCurrencySymbol: 1064181
// AllowDecimalPoint, AllowExponent: Bad Format
//
// Attempting to convert '(0)':
// None: Bad Format
// AllowLeadingWhite, AllowTrailingWhite: Bad Format
// Integer, AllowTrailingSign: Bad Format
// AllowThousands, AllowCurrencySymbol: Bad Format
// AllowDecimalPoint, AllowExponent: Bad Format
//
// Attempting to convert '10241+':
// None: Bad Format
// AllowLeadingWhite, AllowTrailingWhite: Bad Format
// Integer, AllowTrailingSign: 10241
// AllowThousands, AllowCurrencySymbol: Bad Format
// AllowDecimalPoint, AllowExponent: Bad Format
//
// Attempting to convert ' + 21499 ':
// None: Bad Format
// AllowLeadingWhite, AllowTrailingWhite: Bad Format
// Integer, AllowTrailingSign: Bad Format
// AllowThousands, AllowCurrencySymbol: Bad Format
// AllowDecimalPoint, AllowExponent: Bad Format
//
// Attempting to convert ' +21499 ':
// None: Bad Format
// AllowLeadingWhite, AllowTrailingWhite: Bad Format
// Integer, AllowTrailingSign: 21499
// AllowThousands, AllowCurrencySymbol: Bad Format
// AllowDecimalPoint, AllowExponent: Bad Format
//
// Attempting to convert '122153.00':
// None: Bad Format
// AllowLeadingWhite, AllowTrailingWhite: Bad Format
// Integer, AllowTrailingSign: Bad Format
// AllowThousands, AllowCurrencySymbol: Bad Format
// AllowDecimalPoint, AllowExponent: 122153
//
// Attempting to convert '1e03ff':
// None: Bad Format
// AllowLeadingWhite, AllowTrailingWhite: Bad Format
// Integer, AllowTrailingSign: Bad Format
// AllowThousands, AllowCurrencySymbol: Bad Format
// AllowDecimalPoint, AllowExponent: Bad Format
//
// Attempting to convert '91300.0e-2':
// None: Bad Format
// AllowLeadingWhite, AllowTrailingWhite: Bad Format
// Integer, AllowTrailingSign: Bad Format
// AllowThousands, AllowCurrencySymbol: Bad Format
// AllowDecimalPoint, AllowExponent: 913
Imports System.Globalization
Module Example
Public Sub Main()
Dim values() As String = { " 214309 ", "1,064,181", "(0)", "10241+", _
" + 21499 ", " +21499 ", "122153.00", _
"1e03ff", "91300.0e-2" }
Dim whitespace As NumberStyles = NumberStyles.AllowLeadingWhite Or NumberStyles.AllowTrailingWhite
Dim styles() As NumberStyles = { NumberStyles.None, _
whitespace, _
NumberStyles.AllowLeadingSign Or NumberStyles.AllowTrailingSign Or whitespace, _
NumberStyles.AllowThousands Or NumberStyles.AllowCurrencySymbol, _
NumberStyles.AllowExponent Or NumberStyles.AllowDecimalPoint }
' Attempt to convert each number using each style combination.
For Each value As String In values
Console.WriteLine("Attempting to convert '{0}':", value)
For Each style As NumberStyles In styles
Try
Dim number As UInteger = UInt32.Parse(value, style)
Console.WriteLine(" {0}: {1}", style, number)
Catch e As FormatException
Console.WriteLine(" {0}: Bad Format", style)
Catch e As OverflowException
Console.WriteLine(" {0}: Overflow", value)
End Try
Next
Console.WriteLine()
Next
End Sub
End Module
' The example displays the following output:
' Attempting to convert ' 214309 ':
' None: Bad Format
' AllowLeadingWhite, AllowTrailingWhite: 214309
' Integer, AllowTrailingSign: 214309
' AllowThousands, AllowCurrencySymbol: Bad Format
' AllowDecimalPoint, AllowExponent: Bad Format
'
' Attempting to convert '1,064,181':
' None: Bad Format
' AllowLeadingWhite, AllowTrailingWhite: Bad Format
' Integer, AllowTrailingSign: Bad Format
' AllowThousands, AllowCurrencySymbol: 1064181
' AllowDecimalPoint, AllowExponent: Bad Format
'
' Attempting to convert '(0)':
' None: Bad Format
' AllowLeadingWhite, AllowTrailingWhite: Bad Format
' Integer, AllowTrailingSign: Bad Format
' AllowThousands, AllowCurrencySymbol: Bad Format
' AllowDecimalPoint, AllowExponent: Bad Format
'
' Attempting to convert '10241+':
' None: Bad Format
' AllowLeadingWhite, AllowTrailingWhite: Bad Format
' Integer, AllowTrailingSign: 10241
' AllowThousands, AllowCurrencySymbol: Bad Format
' AllowDecimalPoint, AllowExponent: Bad Format
'
' Attempting to convert ' + 21499 ':
' None: Bad Format
' AllowLeadingWhite, AllowTrailingWhite: Bad Format
' Integer, AllowTrailingSign: Bad Format
' AllowThousands, AllowCurrencySymbol: Bad Format
' AllowDecimalPoint, AllowExponent: Bad Format
'
' Attempting to convert ' +21499 ':
' None: Bad Format
' AllowLeadingWhite, AllowTrailingWhite: Bad Format
' Integer, AllowTrailingSign: 21499
' AllowThousands, AllowCurrencySymbol: Bad Format
' AllowDecimalPoint, AllowExponent: Bad Format
'
' Attempting to convert '122153.00':
' None: Bad Format
' AllowLeadingWhite, AllowTrailingWhite: Bad Format
' Integer, AllowTrailingSign: Bad Format
' AllowThousands, AllowCurrencySymbol: Bad Format
' AllowDecimalPoint, AllowExponent: 122153
'
' Attempting to convert '1e03ff':
' None: Bad Format
' AllowLeadingWhite, AllowTrailingWhite: Bad Format
' Integer, AllowTrailingSign: Bad Format
' AllowThousands, AllowCurrencySymbol: Bad Format
' AllowDecimalPoint, AllowExponent: Bad Format
'
' Attempting to convert '91300.0e-2':
' None: Bad Format
' AllowLeadingWhite, AllowTrailingWhite: Bad Format
' Integer, AllowTrailingSign: Bad Format
' AllowThousands, AllowCurrencySymbol: Bad Format
' AllowDecimalPoint, AllowExponent: 913
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 bir bileşimi olmalıdır. parametresi, tarafından temsil s
edilen style
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 s
bu yöntem aşırı yüklemesini kullanışlı s
hale getirir.
değerine style
s
bağlı olarak parametresi aşağıdaki öğeleri içerebilir:
[ws] [$][sign][rakamlar,]rakamlar[.fractional_digits][E[sign]exponential_digits][ws]
Köşeli ayraçlar ([ve]) içindeki öğeler isteğe bağlıdır. içeriyorsa style
NumberStyles.AllowHexSpecifiers
, parametresi aşağıdaki öğeleri içerebilir:
[ws] hexdigits[ws]
Aşağıdaki tablo her öğeyi açıklar.
Öğe | Açıklama |
---|---|
Ws | İsteğe bağlı beyaz boşluk. Bayrağı içeriyorsa başında boşluk ve s style bayrağı içeriyorsa sonunda s style NumberStyles.AllowTrailingWhite görüntülenebilir.NumberStyles.AllowLeadingWhite |
$ | 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 NumberStyles.AllowCurrencySymbol para birimi simgesi içinde s style görünebilir. |
sign | İsteğe bağlı bir işaret. İşaret, bayrağı içeriyorsa başında s style ve bayrağını içeriyorsa NumberStyles.AllowLeadingSignNumberStyles.AllowTrailingSign sonunda s style görüntülenebilir. Parantezler, bayrağı içeriyorsa NumberStyles.AllowParentheses negatif bir değeri style belirtmek için içinde kullanılabilirs . Ancak, negatif işareti simgesi yalnızca sıfır ile kullanılabilir; aksi takdirde, yöntemi bir OverflowExceptionoluşturur. |
Basamak fractional_digits exponential_digits |
0 İle 9 arasında bir basamak dizisi. fractional_digits için yalnızca 0 rakamı geçerlidir. |
, | Kültüre özgü bir grup ayırıcı simge. bayrağını style içeriyorsa geçerli kültürün grup ayırıcısı NumberStyles.AllowThousands içinde s görüntülenebilir. |
. | Bir kültüre özgü ondalık nokta sembolü. bayrağını style içeriyorsa geçerli kültürün NumberStyles.AllowDecimalPoint ondalık noktası simgesi içinde s görüntülenebilir. Ayrıştırma işleminin başarılı olması için kesirli basamak olarak yalnızca 0 rakamı görüntülenebilir; fractional_digits başka bir rakam içeriyorsa, bir FormatException oluşturulur. |
E | Değerin üslü (bilimsel) gösterimle temsil edildiğini gösteren "e" veya "E" karakteri. parametresi, s bayrağını içeriyorsa üstel gösteriminde style bir sayıyı NumberStyles.AllowExponent temsil edebilir. |
hexdigits | 0 İle f veya 0 ile f arasında 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 UInt32 her zaman başarıyla ayrıştırılır. 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 s
bulunabilecek öğ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 ayırıcı (.) ve kesirli basamaklar öğeleri. |
AllowExponent | Exponential_digits ile birlikte üstel gösterimi gösteren "e" veya "E" karakteri. |
AllowLeadingWhite | başındaki s ws öğesi. |
AllowTrailingWhite | sonundaki s ws öğesi. |
AllowLeadingSign | başındaki s sign öğesi. |
AllowTrailingSign | sonundaki s sign öğesi. |
AllowParentheses | Sayısal değeri kapsayan parantez biçimindeki işaret öğesi. |
AllowThousands | Grup ayırıcı (,) öğesi. |
AllowCurrencySymbol | Para birimi ($) öğesi. |
Currency | Tüm öğeler. Ancak, s onaltılık bir sayıyı veya üstel gösterimindeki bir sayıyı temsil edemez. |
Float | öğesinin başında veya sonundaki s ws öğesi, başlangıcını s ve ondalık ayırıcı (.) simgesini imzalar. parametresi üstel s gösterimi de kullanabilir. |
Number | , , grup ayırıcısı (,) ve ondalık ayırıcı (.) öğeleri. sign ws |
Any | Tüm öğeler. Ancak, s onaltılık bir sayıyı temsil edemez. |
içinde belirli stil öğelerinin NumberStyles.AllowHexSpecifiers
bulunmasına izin veren ancak gerektirmeyen diğer NumberStyles 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ı karakter 0-9, A-F ve a-f karakterleridir. "0x" gibi bir ön eke izin verilmez. parametresiyle style
birleştirilebilen diğer bayraklar yalnızca ve NumberStyles.AllowTrailingWhite'tirNumberStyles.AllowLeadingWhite. (Numaralandırma, NumberStyles her iki boşluk bayrağını da içeren bileşik bir sayı stili NumberStyles.HexNumberiçerir.)
parametresiyle style
birleştirilebilen diğer bayraklar yalnızca ve NumberStyles.AllowTrailingWhite'tirNumberStyles.AllowLeadingWhite. (Numaralandırma, NumberStyles her iki boşluk bayrağını da içeren bileşik bir sayı stili NumberStyles.HexNumberiçerir.)
Not
Onaltılık bir sayının dize gösterimi ises
, bunun önünde onaltılık sayı olarak ayırt eden herhangi bir dekorasyon (veya &h
gibi0x
) 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. Biçimlendirme bilgileri ayrıştırma işlemi için kullanılan kültürü belirtmek için aşırı yüklemeyi çağırın Parse(String, NumberStyles, IFormatProvider) .
Ayrıca bkz.
Şunlara uygulanır
Parse(ReadOnlySpan<Char>, IFormatProvider)
- Kaynak:
- UInt32.cs
- Kaynak:
- UInt32.cs
- Kaynak:
- UInt32.cs
Bir karakter aralığını bir değere ayrıştırıyor.
public:
static System::UInt32 Parse(ReadOnlySpan<char> s, IFormatProvider ^ provider) = ISpanParsable<System::UInt32>::Parse;
public static uint Parse (ReadOnlySpan<char> s, IFormatProvider? provider);
static member Parse : ReadOnlySpan<char> * IFormatProvider -> uint32
Public Shared Function Parse (s As ReadOnlySpan(Of Char), provider As IFormatProvider) As UInteger
Parametreler
- s
- ReadOnlySpan<Char>
Ayrıştırılacak karakterlerin yayılması.
- provider
- IFormatProvider
hakkında s
kültüre özgü biçimlendirme bilgileri sağlayan bir nesne.
Döndürülenler
ayrıştırma s
sonucu.
Uygulamalar
Şunlara uygulanır
Parse(ReadOnlySpan<Byte>, IFormatProvider)
- Kaynak:
- UInt32.cs
- Kaynak:
- UInt32.cs
UTF-8 karakterlik bir aralığı bir değere ayrıştırıyor.
public:
static System::UInt32 Parse(ReadOnlySpan<System::Byte> utf8Text, IFormatProvider ^ provider) = IUtf8SpanParsable<System::UInt32>::Parse;
public static uint Parse (ReadOnlySpan<byte> utf8Text, IFormatProvider? provider);
static member Parse : ReadOnlySpan<byte> * IFormatProvider -> uint32
Public Shared Function Parse (utf8Text As ReadOnlySpan(Of Byte), provider As IFormatProvider) As UInteger
Parametreler
- utf8Text
- ReadOnlySpan<Byte>
Ayrıştırılacak UTF-8 karakter aralığı.
- provider
- IFormatProvider
hakkında utf8Text
kültüre özgü biçimlendirme bilgileri sağlayan bir nesne.
Döndürülenler
ayrıştırma utf8Text
sonucu.
Uygulamalar
Şunlara uygulanır
Parse(String)
- Kaynak:
- UInt32.cs
- Kaynak:
- UInt32.cs
- Kaynak:
- UInt32.cs
Bir sayının dize gösterimini 32 bit işaretsiz tamsayı eşdeğerine dönüştürür.
public:
static System::UInt32 Parse(System::String ^ s);
[System.CLSCompliant(false)]
public static uint Parse (string s);
public static uint Parse (string s);
[<System.CLSCompliant(false)>]
static member Parse : string -> uint32
static member Parse : string -> uint32
Public Shared Function Parse (s As String) As UInteger
Parametreler
- s
- String
Dönüştürülecek sayıyı temsil eden bir dize.
Döndürülenler
içinde bulunan s
sayıya eşdeğer bir 32 bit işaretsiz tamsayı.
- Öznitelikler
Özel durumlar
s
parametresidirnull
.
s
Parametresi doğru biçimde değil.
parametresi UInt32.MinValues
değerinden küçük veya UInt32.MaxValue değerinden büyük bir sayıyı temsil eder.
Örnekler
Aşağıdaki örnek, dize değerleri dizisini ayrıştırmak için yöntemini kullanır Parse(String) .
string[] values = { "+13230", "-0", "1,390,146", "$190,235,421,127",
"0xFA1B", "163042", "-10", "2147483648",
"14065839182", "16e07", "134985.0", "-12034" };
foreach (string value in values)
{
try {
uint number = UInt32.Parse(value);
Console.WriteLine("{0} --> {1}", value, number);
}
catch (FormatException) {
Console.WriteLine("{0}: Bad Format", value);
}
catch (OverflowException) {
Console.WriteLine("{0}: Overflow", value);
}
}
// The example displays the following output:
// +13230 --> 13230
// -0 --> 0
// 1,390,146: Bad Format
// $190,235,421,127: Bad Format
// 0xFA1B: Bad Format
// 163042 --> 163042
// -10: Overflow
// 2147483648 --> 2147483648
// 14065839182: Overflow
// 16e07: Bad Format
// 134985.0: Bad Format
// -12034: Overflow
open System
let values =
[| "+13230"; "-0"; "1,390,146"; "$190,235,421,127"
"0xFA1B"; "163042"; "-10"; "2147483648"
"14065839182"; "16e07"; "134985.0"; "-12034" |]
for value in values do
try
let number = UInt32.Parse value
printfn $"{value} --> {number}"
with
| :? FormatException ->
printfn $"{value}: Bad Format"
| :? OverflowException ->
printfn $"{value}: Overflow"
// The example displays the following output:
// +13230 --> 13230
// -0 --> 0
// 1,390,146: Bad Format
// $190,235,421,127: Bad Format
// 0xFA1B: Bad Format
// 163042 --> 163042
// -10: Overflow
// 2147483648 --> 2147483648
// 14065839182: Overflow
// 16e07: Bad Format
// 134985.0: Bad Format
// -12034: Overflow
Dim values() As String = { "+13230", "-0", "1,390,146", "$190,235,421,127",
"0xFA1B", "163042", "-10", "2147483648",
"14065839182", "16e07", "134985.0", "-12034" }
For Each value As String In values
Try
Dim number As UInteger = UInt32.Parse(value)
Console.WriteLine("{0} --> {1}", value, number)
Catch e As FormatException
Console.WriteLine("{0}: Bad Format", value)
Catch e As OverflowException
Console.WriteLine("{0}: Overflow", value)
End Try
Next
' The example displays the following output:
' +13230 --> 13230
' -0 --> 0
' 1,390,146: Bad Format
' $190,235,421,127: Bad Format
' 0xFA1B: Bad Format
' 163042 --> 163042
' -10: Overflow
' 2147483648 --> 2147483648
' 14065839182: Overflow
' 16e07: Bad Format
' 134985.0: Bad Format
' -12034: Overflow
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çlar ([ve]) içindeki öğeler isteğe bağlıdır. Aşağıdaki tablo her öğeyi açıklar.
Öğe | Açıklama |
---|---|
Ws | İsteğe bağlı beyaz boşluk. |
sign | İ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şareti simgesi yalnızca sıfır ile kullanılabilir; aksi takdirde, yöntemi bir OverflowExceptionoluşturur. |
Basamak | 0 İle 9 arasında değişen bir basamak dizisi. Baştaki sıfırlar dikkate alınmaz. |
Not
parametresi tarafından s
belirtilen dize, stil kullanılarak NumberStyles.Integer yorumlanır. Herhangi 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
Geri Bildirim
https://aka.ms/ContentUserFeedback.
Çok yakında: 2024 boyunca, içerik için geri bildirim mekanizması olarak GitHub Sorunları’nı kullanımdan kaldıracak ve yeni bir geri bildirim sistemiyle değiştireceğiz. Daha fazla bilgi için bkz.Gönderin ve geri bildirimi görüntüleyin