SByte.Parse Method converts string is in a style and culture-specific format to 8-bit signed equivalent.
Imports System.Globalization
Module modMain
Public Sub Main()
Dim byteString As String
byteString = " 123"
ParseString(byteString, NumberStyles.None)
ParseString(byteString, NumberStyles.Integer)
End Sub
Private Sub ParseString(value As String, style As NumberStyles)
Dim number As SByte
Try
number = SByte.Parse(value, style, NumberFormatInfo.CurrentInfo)
Console.WriteLine("SByte.Parse(""{0}"", {1})) = {2}", value, style.ToString, number)
Catch e As Exception
Console.WriteLine("'{0}' and {1} throw a {2}", value, style.ToString, e.GetType.Name)
End Try
End Sub
End Module
Related examples in the same category