SByte.TryParse tries to convert string in a style and culture-specific format to SByte : SByte « Data Types « VB.Net






SByte.TryParse tries to convert string in a style and culture-specific format to SByte

 

Imports System.Globalization

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

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

      numericString = "-1"
      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 = "1E-01"
      styles = NumberStyles.Integer Or NumberStyles.AllowExponent
      CallTryParse(numericString, styles) 

      numericString = "12E-01"
      CallTryParse(numericString, styles)

      numericString = "12E01"
      CallTryParse(numericString, styles) 

      numericString = "C8"
      CallTryParse(numericString, NumberStyles.HexNumber)

      numericString = "0x8C"
      CallTryParse(numericString, NumberStyles.HexNumber)
   End Sub

   Private Sub CallTryParse(stringToConvert As String, styles AS NumberStyles)
      Dim number As SByte
      Dim result As Boolean = SByte.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.Use the Sign(SByte) method to determine the sign of a SByte value and display it to the console.
2.SByte.MaxValue represents the largest possible value of SByte.
3.SByte.Parse converts string number to 8-bit signed integer.
4.SByte.Parse converts string in a culture-specific format to its 8-bit signed integer
5.SByte.Parse converts string in a style to 8-bit signed integer equivalent.
6.SByte.Parse Method converts string is in a style and culture-specific format to 8-bit signed equivalent.
7.SByte.ToString converts its string using the specified culture-specific format information.
8.SByte.ToString converts to string representation using the specified format.
9.SByte.ToString Method converts to string using the specified format and culture-specific format information.
10.SByte.TryParse tries to convert string to SByte equivalent
11.Assign SByte to Integer