String programming in C#

How to Reverse a word from the sentences:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Programing
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("String");
            string str=Console.ReadLine();
         
            string[] arySource = str.Split(' ');
            string strReverse = string.Empty;
            int length = Convert.ToInt32(arySource.Length);
            for (int i = length - 1; i >= 0; i--)
            {
                strReverse = strReverse + " "  + arySource[i];
            }
              Console.WriteLine("Original: " + str);
              Console.WriteLine("Reverse: " + strReverse);
              Console.ReadLine();
         
               }
     

        }
    }

i/P=hi how are you
o/p=you are how hi


How To Reverse a whole string

 public class Program
    {
        public static void Main(string[] args)
        {
              // string input = "hello world";
            string input = Console.ReadLine();
               string output = "";
             for (int i = input.Length - 1; i >= 0; i--)
             {
                 output += input[i];
              }
            Console.WriteLine(output);
        }
    }

I/P =My name is jaideep
O/P=peediaj si eman ym

Comments

Popular posts from this blog

Prime Number Program in C#

Fibonacci Series in C#

Temporary tables