Byte.TryParse converts string in a style and culture-specific format to Byte
Imports System.Globalization
Module ByteConversion2
Public Sub Main()
Dim byteString As String
Dim styles As NumberStyles
byteString = "1024"
styles = NumberStyles.Integer
CallTryParse(byteString, styles)
End Sub
Private Sub CallTryParse(stringToConvert As String, styles As NumberStyles)
Dim byteValue As Byte
Dim result As Boolean = Byte.TryParse(stringToConvert, styles, Nothing, byteValue)
If result Then
Console.WriteLine("Converted '{0}' to {1}",stringToConvert, byteValue)
Else
If stringToConvert Is Nothing Then stringToConvert = ""
Console.WriteLine("Attempted conversion of '{0}' failed.",stringToConvert.ToString())
End If
End Sub
End Module
Related examples in the same category