Convert.ToByte(String,IFormatProvider) converts string to 8-bit unsigned integer, using culture-specific format
Imports System.Globalization
Module Example
Public Sub Main()
Dim provider As New NumberFormatInfo()
With provider
.PositiveSign = "pos "
.NegativeSign = "neg "
.NumberDecimalSeparator = "."
End With
Dim numericStrings() As String = { "234", "+234", "pos 234", "234.", _
"255", "256", "-1" }
For Each numericString As String In numericStrings
Console.Write("'{0,-8}' -> ", numericString)
Try
Dim number As Byte = Convert.ToByte(numericString, provider)
Console.WriteLine(number)
Catch ex As FormatException
Console.WriteLine("Incorrect Format")
Catch ex As OverflowException
Console.WriteLine("Overflows a Byte")
End Try
Next
End Sub
End Module
Related examples in the same category