SByte.Parse converts string in a culture-specific format to its 8-bit signed integer
Imports System.Globalization
Module Example
Public Sub Main()
Dim nf As New NumberFormatInfo()
nf.NegativeSign = "~"
Dim values() As String = { "-1", "+12", "~16", " 1", "~255" }
Dim providers() As IFormatProvider = { nf, CultureInfo.InvariantCulture }
For Each provider As IFormatProvider In providers
Console.WriteLine("Conversions using {0}:", CObj(provider).GetType().Name)
For Each value As String In values
Try
Console.WriteLine(" Converted '{0}' to {1}.", _
value, SByte.Parse(value, provider))
Catch e As FormatException
Console.WriteLine(" Unable to parse '{0}'.", value)
Catch e As OverflowException
Console.WriteLine(" '{0}' is out of range of the SByte type.", value)
End Try
Next
Next
End Sub
End Module
Related examples in the same category