本文整理汇总了VB.NET中System.Byte.Parse方法的典型用法代码示例。如果您正苦于以下问题:VB.NET Byte.Parse方法的具体用法?VB.NET Byte.Parse怎么用?VB.NET Byte.Parse使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Byte 的用法示例。
在下文中一共展示了Byte.Parse方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的VB.NET代码示例。
示例1:
Dim style As NumberStyles
Dim culture As CultureInfo
Dim value As String
Dim number As Byte
' Parse number with decimals.
' NumberStyles.Float includes NumberStyles.AllowDecimalPoint.
style = NumberStyles.Float
culture = CultureInfo.CreateSpecificCulture("fr-FR")
value = "12,000"
number = Byte.Parse(value, style, culture)
Console.WriteLine("Converted '{0}' to {1}.", value, number)
culture = CultureInfo.CreateSpecificCulture("en-GB")
Try
number = Byte.Parse(value, style, culture)
Console.WriteLine("Converted '{0}' to {1}.", value, number)
Catch e As FormatException
Console.WriteLine("Unable to parse '{0}'.", value)
End Try
value = "12.000"
number = Byte.Parse(value, style, culture)
Console.WriteLine("Converted '{0}' to {1}.", value, number)
开发者ID:VB.NET开发者,项目名称:System,代码行数:25,代码来源:Byte.Parse 输出:
Converted '12,000' to 12.
Unable to parse '12,000'.
Converted '12.000' to 12.
示例2:
Dim value As String
Dim style As NumberStyles
Dim number As Byte
' Parse value with no styles allowed.
style = NumberStyles.None
value = " 241 "
Try
number = Byte.Parse(value, style)
Console.WriteLine("Converted '{0}' to {1}.", value, number)
Catch e As FormatException
Console.WriteLine("Unable to parse '{0}'.", value)
End Try
' Parse value with trailing sign.
style = NumberStyles.Integer Or NumberStyles.AllowTrailingSign
value = " 163+"
number = Byte.Parse(value, style)
Console.WriteLine("Converted '{0}' to {1}.", value, number)
' Parse value with leading sign.
value = " +253 "
number = Byte.Parse(value, style)
Console.WriteLine("Converted '{0}' to {1}.", value, number)
' This example displays the following output to the console:
' Unable to parse ' 241 '.
' Converted ' 163+' to 163.
' Converted ' +253 ' to 253.
开发者ID:VB.NET开发者,项目名称:System,代码行数:28,代码来源:Byte.Parse
示例3:
Dim stringToConvert As String = " 162"
Dim byteValue As Byte
Try
byteValue = Byte.Parse(stringToConvert)
Console.WriteLine("Converted '{0}' to {1}.", stringToConvert, byteValue)
Catch e As FormatException
Console.WriteLine("Unable to parse '{0}'.", stringToConvert)
Catch e As OverflowException
Console.WriteLine("'{0}' is greater than {1} or less than {2}.", _
stringToConvert, Byte.MaxValue, Byte.MinValue)
End Try
开发者ID:VB.NET开发者,项目名称:System,代码行数:11,代码来源:Byte.Parse 输出:
Converted ' 162' to 162.
示例4:
Dim stringToConvert As String
Dim byteValue As Byte
stringToConvert = " 214 "
Try
byteValue = Byte.Parse(stringToConvert, CultureInfo.InvariantCulture)
Console.WriteLine("Converted '{0}' to {1}.", stringToConvert, byteValue)
Catch e As FormatException
Console.WriteLine("Unable to parse '{0}'.", stringToConvert)
Catch e As OverflowException
Console.WriteLine("'{0}' is greater than {1} or less than {2}.", _
stringToConvert, Byte.MaxValue, Byte.MinValue)
End Try
stringToConvert = " + 214 "
Try
byteValue = Byte.Parse(stringToConvert, CultureInfo.InvariantCulture)
Console.WriteLine("Converted '{0}' to {1}.", stringToConvert, byteValue)
Catch e As FormatException
Console.WriteLine("Unable to parse '{0}'.", stringToConvert)
Catch e As OverflowException
Console.WriteLine("'{0}' is greater than {1} or less than {2}.", _
stringToConvert, Byte.MaxValue, Byte.MinValue)
End Try
stringToConvert = " +214 "
Try
byteValue = Byte.Parse(stringToConvert, CultureInfo.InvariantCulture)
Console.WriteLine("Converted '{0}' to {1}.", stringToConvert, byteValue)
Catch e As FormatException
Console.WriteLine("Unable to parse '{0}'.", stringToConvert)
Catch e As OverflowException
Console.WriteLine("'{0}' is greater than {1} or less than {2}.", _
stringToConvert, Byte.MaxValue, Byte.MinValue)
End Try
开发者ID:VB.NET开发者,项目名称:System,代码行数:35,代码来源:Byte.Parse 输出:
Converted ' 214 ' to 214.
Unable to parse ' + 214 '.
Converted ' +214 ' to 214.
注:本文中的System.Byte.Parse方法示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论