Click here to Skip to main content
Click here to Skip to main content

Tagged as

Reverse of a string without using the Reverse function in C# and VB

, 26 Jul 2011
Rate this:
Please Sign up or sign in to vote.
How to reverse a string without using the Reverse function in C# and VB.

This is a simple code snippet for reversing a string without using the Reverse function. For example, we have a string "KUMAR"; without using a function, we can reverse it using the code snippet below. Code is given in both C# and VBalso. This will be helpful to beginners. If you have any queries, please feel free to ask me.

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();
    }
}
VB:
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

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

hemantwithu
Software Developer
India India
No Biography provided

Comments and Discussions

 
GeneralMy vote of 1 PinmvpSergey Alexandrovich Kryukov6-Jul-14 20:56 
GeneralMy vote of 1 PinmemberMember 1058994326-Jun-14 21:48 
Generalwhats the point of this ? PinmemberXmen W.K.27-Jul-11 0:10 
GeneralReason for my vote of 1 What is the utility of this? PinmemberJaime Olivares25-Jul-11 16:35 
GeneralReason for my vote of 1 Globally known age old problem since... PinmvpPrerak Patel22-Jul-11 23:45 
General[edit] removed email address. PinsubeditorIndivara22-Jul-11 12:14 
GeneralFew notes PinmemberMika Wendelius22-Jul-11 0:55 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Mobile
Web02 | 2.8.140827.1 | Last Updated 26 Jul 2011
Article Copyright 2011 by hemantwithu
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid