Convert.ToInt32 (String, IFormatProvider) converts string to 32-bit signed integer using culture-specific format
Imports System.Globalization
Module Example
Public Sub Main()
Dim customProvider As New NumberFormatInfo()
customProvider.NegativeSign = "neg "
customProvider.PositiveSign = "pos "
Dim providers() As NumberFormatInfo = { customProvider, NumberFormatInfo.InvariantInfo }
Dim numericStrings() As String = { "123456789", "+123456789", "pos 123456789", _
"-666666666" }
For ctr As Integer = 0 To 1
Dim provider As IFormatPRovider = providers(ctr)
Console.WriteLine(IIf(ctr = 0, "Custom Provider:", "Invariant Provider:"))
For Each numericString As String In numericStrings
Console.Write("{0,15} --> ", numericString)
Try
Console.WriteLine(Convert.ToInt32(numericString, provider))
Catch e As Exception
Console.WriteLine("OverflowException")
End Try
Next
Next
End Sub
End Module
Related examples in the same category