How to reverse a string?



How to reverse a string?

public String ReverseAstirng(String x)
        {
            char[] arr = x.ToCharArray();
            int leng = arr.Length;
            string rev="";
            for (int i = arr.Length-1; i >=0 ; i--)
            {
                rev  = rev + arr[i].ToString();
            }
            return rev;
         }
        static void Main(string[] args)
        {
            Program p1 = new Program();
            Console.WriteLine(" How to reverse a string ? ");
            Console.WriteLine("Reverse String = "+ p1.ReverseAstirng("shivKumar"));
            Console.ReadLine();
        }
OutPut:
 How to reverse a string ?
Reverse String = ramuKvihs





Share:

No comments:

Post a Comment

Popular

Tags

Mobile

Recent Posts