Mega Code Archive

 
Categories / VB.Net / Development
 

Convert ToInt64(String, IFormatProvider) converts string to 64-bit signed integer using culture-specific format

Imports System.Globalization Public 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", "+123456","pos 12345", "-123", _                                          "neg 123456789", "9.","13,456,789", "(123)", "-9" }       For ctr As Integer = 0 to 1          Dim provider As IFormatProvider = providers(ctr)          Console.WriteLine(IIf(ctr = 0, "Custom Provider:", "Invariant Culture:"))          For Each numericString As String In numericStrings             Console.Write(numericString)             Try                Console.WriteLine("{0,22}", Convert.ToInt32(numericString, provider))             Catch e As Exception                Console.WriteLine("Exception")             End Try          Next          Console.WriteLine()       Next    End Sub  End Module