• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

VB.NET BigInteger.Parse方法代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了VB.NET中System.Numerics.BigInteger.Parse方法的典型用法代码示例。如果您正苦于以下问题:VB.NET BigInteger.Parse方法的具体用法?VB.NET BigInteger.Parse怎么用?VB.NET BigInteger.Parse使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Numerics.BigInteger的用法示例。



在下文中一共展示了BigInteger.Parse方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的VB.NET代码示例。

示例1:

Dim stringToParse As String = String.Empty
Try
   ' Parse two strings.
   Dim string1, string2 As String
   string1 = "12347534159895123"
   string2 = "987654321357159852"
   stringToParse = string1
   Dim number1 As BigInteger = BigInteger.Parse(stringToParse)
   Console.WriteLine("Converted '{0}' to {1:N0}.", stringToParse, number1)
   stringToParse = string2
   Dim number2 As BigInteger = BigInteger.Parse(stringToParse)
   Console.WriteLine("Converted '{0}' to {1:N0}.", stringToParse, number2)
   ' Perform arithmetic operations on the two numbers.
   number1 *= 3
   number2 *= 2
   ' Compare the numbers.
   Select Case BigInteger.Compare(number1, number2)
      Case -1
         Console.WriteLine("{0} is greater than {1}.", number2, number1)
      Case 0
         Console.WriteLine("{0} is equal to {1}.", number1, number2)
      Case 1
         Console.WriteLine("{0} is greater than {1}.", number1, number2)
   End Select      
Catch e As FormatException
   Console.WriteLine("Unable to parse {0}.", stringToParse)
End Try
开发者ID:VB.NET开发者,项目名称:System.Numerics,代码行数:27,代码来源:BigInteger.Parse

输出:

Converted '12347534159895123' to 12,347,534,159,895,123.
Converted '987654321357159852' to 987,654,321,357,159,852.
1975308642714319704 is greater than 37042602479685369.


示例2: succeed

Dim number As BigInteger 
' Method should succeed (white space and sign allowed)
number = BigInteger.Parse("   -68054   ", NumberStyles.Integer)
Console.WriteLine(number)
' Method should succeed (string interpreted as hexadecimal)
number = BigInteger.Parse("68054", NumberStyles.AllowHexSpecifier)
Console.WriteLine(number)
' Method call should fail: sign not allowed
Try
   number = BigInteger.Parse("   -68054  ", NumberStyles.AllowLeadingWhite _
                                            Or NumberStyles.AllowTrailingWhite)
   Console.WriteLine(number)
Catch e As FormatException
   Console.WriteLine(e.Message)
End Try                                                     
' Method call should fail: white space not allowed
Try
   number = BigInteger.Parse("   68054  ", NumberStyles.AllowLeadingSign)
   Console.WriteLine(number)
Catch e As FormatException
   Console.WriteLine(e.Message)
End Try
开发者ID:VB.NET开发者,项目名称:System.Numerics,代码行数:22,代码来源:BigInteger.Parse

输出:

-68054
426068
Input string was not in a correct format.
Input string was not in a correct format.


示例3: Example

' 导入命名空间
Imports System.Globalization
Imports System.Numerics

Module Example
   Public Sub Main()
      Dim hexStrings() As String = { "80", "E293", "F9A2FF", "FFFFFFFF", 
                                     "080", "0E293", "0F9A2FF", "0FFFFFFFF",  
                                     "0080", "00E293", "00F9A2FF", "00FFFFFFFF" }
      For Each hexString As String In hexStrings
         Dim number As BigInteger = BigInteger.Parse(hexString, NumberStyles.AllowHexSpecifier)
         Console.WriteLine("Converted 0x{0} to {1}.", hexString, number)
      Next         
   End Sub
End Module
开发者ID:VB.NET开发者,项目名称:System.Numerics,代码行数:15,代码来源:BigInteger.Parse

输出:

Converted 0x80 to -128.
Converted 0xE293 to -7533.
Converted 0xF9A2FF to -417025.
Converted 0xFFFFFFFF to -1.
Converted 0x080 to 128.
Converted 0x0E293 to 58003.
Converted 0x0F9A2FF to 16360191.
Converted 0x0FFFFFFFF to 4294967295.
Converted 0x0080 to 128.
Converted 0x00E293 to 58003.
Converted 0x00F9A2FF to 16360191.
Converted 0x00FFFFFFFF to 4294967295.


示例4: GetFormat

Public Class BigIntegerFormatProvider : Implements IFormatProvider
   Public Function GetFormat(formatType As Type) As Object _
                            Implements IFormatProvider.GetFormat
      If formatType Is GetType(NumberFormatInfo) Then
         Dim numberFormat As New NumberFormatInfo
         numberFormat.NegativeSign = "~"
         Return numberFormat
      Else
         Return Nothing
      End If      
   End Function
End Class
开发者ID:VB.NET开发者,项目名称:System.Numerics,代码行数:12,代码来源:BigInteger.Parse


示例5:

Dim number As BigInteger = BigInteger.Parse("~6354129876", New BigIntegerFormatProvider)
' Display value using same formatting information
Console.WriteLine(number.ToString(New BigIntegerFormatProvider))
' Display value using formatting of current culture
Console.WriteLine(number)
开发者ID:VB.NET开发者,项目名称:System.Numerics,代码行数:5,代码来源:BigInteger.Parse


示例6: NumberFormatInfo

Dim fmt As New NumberFormatInfo()
fmt.NegativeSign = "~"

Dim number As BigInteger = BigInteger.Parse("~6354129876", fmt)
' Display value using same formatting information
Console.WriteLine(number.ToString(fmt))
' Display value using formatting of current culture
Console.WriteLine(number)
开发者ID:VB.NET开发者,项目名称:System.Numerics,代码行数:8,代码来源:BigInteger.Parse


示例7: BigIntegerFormatProvider

' Call parse with default values of style and provider
Console.WriteLine(BigInteger.Parse("  -300   ", _
                  NumberStyles.Integer, CultureInfo.CurrentCulture))
' Call parse with default values of style and provider supporting tilde as negative sign
Console.WriteLine(BigInteger.Parse("   ~300  ", _
                                   NumberStyles.Integer, New BigIntegerFormatProvider()))
' Call parse with only AllowLeadingWhite and AllowTrailingWhite
' Exception thrown because of presence of negative sign
Try
   Console.WriteLIne(BigInteger.Parse("    ~300   ", _
                                      NumberStyles.AllowLeadingWhite Or NumberStyles.AllowTrailingWhite, _
                                      New BigIntegerFormatProvider()))
Catch e As FormatException
   Console.WriteLine("{0}: {1}   {2}", e.GetType().Name, vbCrLf, e.Message)
End Try                                   
' Call parse with only AllowHexSpecifier
' Exception thrown because of presence of negative sign
Try
   Console.WriteLIne(BigInteger.Parse("-3af", NumberStyles.AllowHexSpecifier, _
                                      New BigIntegerFormatProvider()))
Catch e As FormatException
   Console.WriteLine("{0}: {1}   {2}", e.GetType().Name, vbCrLf, e.Message)
End Try                                 
' Call parse with only NumberStyles.None
' Exception thrown because of presence of white space and sign
Try
   Console.WriteLIne(BigInteger.Parse(" -300 ", NumberStyles.None, _
                                      New BigIntegerFormatProvider()))
Catch e As FormatException
   Console.WriteLine("{0}: {1}   {2}", e.GetType().Name, vbCrLf, e.Message)
End Try
开发者ID:VB.NET开发者,项目名称:System.Numerics,代码行数:31,代码来源:BigInteger.Parse

输出:

-300
-300
FormatException:
The value could not be parsed.
FormatException:
The value could not be parsed.
FormatException:
The value could not be parsed.



注:本文中的System.Numerics.BigInteger.Parse方法示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
VB.NET Complex.Multiply方法代码示例发布时间:2022-05-24
下一篇:
VB.NET WebPermission.FromXml方法代码示例发布时间:2022-05-24
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap