Parse value with trailing sign
Imports System.Globalization
Module Example
Public Sub Main()
Dim style As NumberStyles
Dim number As SByte
Dim values1() As String = { " 121 ", "121", "-121" }
style = NumberStyles.None
Console.WriteLine("Styles: {0}", style.ToString())
style = NumberStyles.Integer Or NumberStyles.AllowTrailingSign
Dim values2() As String = { " 103+", " 103 +", "+103", "(103)", " +103 " }
Console.WriteLine("Styles: {0}", style.ToString())
For Each value As String In values2
Try
number = SByte.Parse(value, style)
Console.WriteLine(" Converted '{0}' to {1}.", value, number)
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
End Sub
End Module
Related examples in the same category