Int16.TryParse(String, NumberStyles, IFormatProvider, Int16%) method with a number of different string values. : Integer Parser « Data Types « VB.Net

Home
VB.Net
1.2D
2.Application
3.Class
4.Data Structure
5.Data Types
6.Database ADO.net
7.Development
8.Event
9.File Directory
10.Generics
11.GUI
12.Language Basics
13.LINQ
14.Network Remote
15.Security
16.Thread
17.Windows Presentation Foundation
18.Windows System
19.XML
20.XML LINQ
VB.Net Tutorial
VB.Net by API
VB.Net » Data Types » Integer ParserScreenshots 
Int16.TryParse(String, NumberStyles, IFormatProvider, Int16%) method with a number of different string values.
  

Imports System.Globalization

Module MainClass
   Public Sub Main()
      Dim numericString As String
      Dim styles As NumberStyles

      numericString = "1"
      styles = NumberStyles.Integer
      CallTryParse(numericString, styles)


      numericString = "-30677"
      styles = NumberStyles.None
      CallTryParse(numericString, styles)

      numericString = "1.00"
      styles = NumberStyles.Integer Or NumberStyles.AllowDecimalPoint
      CallTryParse(numericString, styles)

      numericString = "1.72"
      styles = NumberStyles.Integer Or NumberStyles.AllowDecimalPoint
      CallTryParse(numericString, styles)

      numericString = "2,593" 
      styles = NumberStyles.Integer Or NumberStyles.AllowThousands
      CallTryParse(numericString, styles)

      numericString = "11232E-01"
      styles = NumberStyles.Integer Or NumberStyles.AllowExponent
      CallTryParse(numericString, styles

      numericString = "12E01233"
      CallTryParse(numericString, styles

      numericString = "81230c1"
      CallTryParse(numericString, NumberStyles.HexNumber)

      numericString = "0x80C1"
      CallTryParse(numericString, NumberStyles.HexNumber)

   End Sub

   Private Sub CallTryParse(stringToConvert As String, styles AS NumberStyles)
      Dim number As Short
      Dim result As Boolean = Int16.TryParse(stringToConvert, styles,CultureInfo.InvariantCulture, number)
      If result Then
         Console.WriteLine("Converted '{0}' to {1}.", stringToConvert, number)
      Else
         Console.WriteLine("Attempted conversion of '{0}' failed.",Convert.ToString(stringToConvert))
      End If                                                                           
   End Sub
End Module

   
    
  
Related examples in the same category
1.Validate an IntegerValidate an Integer
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.