當前位置: 首頁>>代碼示例>>VB.NET>>正文


VB.NET UInt64.Parse方法代碼示例

本文整理匯總了VB.NET中System.UInt64.Parse方法的典型用法代碼示例。如果您正苦於以下問題:VB.NET UInt64.Parse方法的具體用法?VB.NET UInt64.Parse怎麽用?VB.NET UInt64.Parse使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。


在下文中一共展示了UInt64.Parse方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的VB.NET代碼示例。

示例1: Example

' 導入命名空間
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
開發者ID:VB.NET開發者,項目名稱:System,代碼行數:34,代碼來源:UInt64.Parse

輸出:

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.

示例2: Example

' 導入命名空間
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
開發者ID:VB.NET開發者,項目名稱:System,代碼行數:32,代碼來源:UInt64.Parse

輸出:

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

示例3: values

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
開發者ID:VB.NET開發者,項目名稱:System,代碼行數:13,代碼來源:UInt64.Parse

輸出:

+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

示例4: CultureInfo

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
開發者ID:VB.NET開發者,項目名稱:System,代碼行數:28,代碼來源:UInt64.Parse


注:本文中的System.UInt64.Parse方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。