Convert.ToInt32 (String, IFormatProvider) converts string to 32-bit signed integer using culture-specific format : Convert to Int32 « Development « VB.Net






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

1.Convert.ToInt32 (Boolean) converts Boolean value to 32-bit signed integer.
2.Convert.ToInt32 (Byte) converts 8-bit unsigned integer to 32-bit signed integer.
3.Convert.ToInt32 (Char) converts Unicode character to 32-bit signed integer.
4.Convert.ToInt32 (Decimal) converts decimal number to 32-bit signed integer.
5.Convert.ToInt32 (Double) converts double number to 32-bit signed integer.
6.Convert.ToInt32 (Int16) converts 16-bit signed integer to 32-bit signed integer.
7.Convert.ToInt32 (Int64) converts 64-bit signed integer to 32-bit signed integer.
8.Convert.ToInt32 (Object) converts the value of the specified object to a 32-bit signed integer.
9.Convert.ToInt32 (SByte) converts 8-bit signed integer to 32-bit signed integer.
10.Convert.ToInt32 (Single) converts single-precision floating-point number to 32-bit signed integer.
11.Convert.ToInt32 (String) converts string to an equivalent 32-bit signed integer.
12.Convert.ToInt32 (String, Int32) converts string in a base to 32-bit signed integer.
13.Convert.ToInt32 (UInt16) converts 16-bit unsigned integer to 32-bit signed integer.
14.Convert.ToInt32 (UInt32) converts 32-bit unsigned integer to 32-bit signed integer.
15.Convert.ToInt32 (UInt64) converts 64-bit unsigned integer to an equivalent 32-bit signed integer.