Reverse of a String without using String Reverse Function

Hemanthlaxmi
Posted by Hemanthlaxmi under C# category on | Points: 40 | Views : 4404
This is a simple code snippet for reversing a string without using Reverse Function.For example we have a string "KUMAR" without using function we can reverse it using this code snippet.This code is given in both C# and Vb also.This is will be more helpful to the learners.If any queries please feel free to ask me hemanthlaxmi2011@live.com.

In C#
class ReverseString
{
public static void Main(string[] args)
{
string Name = "He is palying in a ground.";
char[] characters = Name.ToCharArray();
StringBuilder sb = new StringBuilder();
for (int i = Name.Length - 1; i >= 0; --i)
{
sb.Append(characters[i]);
}
Console.Write(sb.ToString());
Console.Read();
}
}


In Vb.NET
Class ReverseString
Public Shared Sub Main(args As String())
Dim Name As String = "He is palying in a ground."
Dim characters As Char() = Name.ToCharArray()
Dim sb As New StringBuilder()
For i As Integer = Name.Length - 1 To 0 Step -1
sb.Append(characters(i))
Next
Console.Write(sb.ToString())
Console.Read()
End Sub
End Class

Comments or Responses

Login to post response