You are on page 1of 3

7.

REVERSE THE GIVEN STRING

July 10, 2014

Aim:
~~~~
To write a program to perform reverses the given string using vb.net.
Procedure:
~~~~~~~~~
Step1: Start the program in the Microsoft Visual Studio 2010.
Step2: File->new->project Select the project type as visual basic and select
the visual studio installed template as console application.
Step3: Choose a Name, Location and Solution name.
Step4: Declare the variables get an input string as str and assign an i variable as 0.
Step5: Using for Each loop to assign a=str and increment a k values as 1.
Step6: Using while loop to check the condition as i>0.
Step7: Finally the output is stored in b.
Step8: End of the program.

12PA01

Page 20

7. REVERSE THE GIVEN STRING

July 10, 2014

Coding:
~~~~~~
Module Module1
Sub Main()
Dim str As String
Dim a(20), b(20) As Char
Dim i, k As Integer
Console.WriteLine("Reverse the string")
Console.WriteLine("****************")
Console.WriteLine("Input")
Console.WriteLine("~~~~")
Console.WriteLine("Enter the string :")
str = Console.ReadLine()
i=0
For Each element As Char In str
a = str
i=i+1
Next
k=0
While i > 0
i=i-1
b(k) = a(i)
k=k+1
End While
Console.WriteLine("Output")
Console.WriteLine("~~~~~~")
Console.WriteLine(b)
Console.ReadKey()
End Sub
End Module

12PA01

Page 21

7. REVERSE THE GIVEN STRING

July 10, 2014

Output:
~~~~~~
Reverse the string
****************
Input
~~~~
Enter the string :
reverse
Output
~~~~~~
esrever

Result:
******
Thus the reverse the given string program was successfully performed.

12PA01

Page 22

You might also like