Parsing Values from String Data

The .NET data types provide the ability to generate a variable of their underlying type given a textual equivalent (e.g., parsing). This technique can be extremely helpful when you wish to convert a bit of user input data (such as a selection from a GUI-based drop-down list box) into a numerical value. Consider the following parsing logic:

' Fun with parsing.

Dim b As Boolean = Boolean.Parse("True") Console.WriteLine("Value of myBool: {0}", b)

Dim d As Double = Double.Parse("99.884") Console.WriteLine("Value of myDbl: {0}", d)

Dim i As Integer = Integer.Parse("8") Console.WriteLine("Value of myInt: {0}", i)

Dim c As Char = Char.Parse("w") Console.WriteLine("Value of myChar: {0}", c)

Source Code The BasicDataTypes project is located under the Chapter 3 subdirectory.

Was this article helpful?

0 0

Post a comment