Showing posts with label Split Strings. Show all posts
Showing posts with label Split Strings. Show all posts

Monday, September 6, 2010

Spliting Strings in Visual Basic

This post demonstrates how to split strings such as "2+2"

Create a Visual Basic Console Application in Visual Studio and Write the following code to split the strings:

Dim i As String = "2+2"
Dim d As Array = i.Split("+")

The Split Method Splits the strings in several parts using the character with which they are separated which is "+" in this case and then it returns an Array. Now write code to convert them to Integer.

Dim a As Integer = Convert.ToInt32(d(0))
Dim b As Integer = Convert.ToInt32(d(1))

Now lets verify that our String was correctly separated.

Console.WriteLine(Convert.ToString(a + b))

Our Console Application should write : 4 .

Please contact me at mauhib@gmail.com and send me your suggestions.

Share the Knowledge

My Card