String Reverse Program

 

  1. namespace Reverse  
  2. {  
  3.     using System;  
  4.     public class StringReverse  
  5.     {  
  6.         public static void Main(string[] args)  
  7.         {  
  8.             Console.WriteLine("Enter the string to reverse : \n");  
  9.             string text = Console.ReadLine();  
  10.             int string_Length = text.Length - 1;  
  11.             string string1 = string.Empty;  
  12.             string string2 = string.Empty;  
  13.             string string3 = string.Empty;  
  14.             while (string_Length >= 0)  
  15.             {  
  16.                 //Verfying spaces between string.  
  17.                 if (text[string_Length].Equals(' '))  
  18.                 {  
  19.                     int i = string1.Length - 1;  
  20.                     while (i >= 0)  
  21.                     {  
  22.                         string2 = string2 + string1[i];  
  23.                         i--;  
  24.                     }  
  25.   
  26.                     string1 = string.Empty;  
  27.                     string2 = string2 + ' ';  
  28.                     string_Length--;  
  29.                 }  
  30.                 else  
  31.                 {  
  32.                     string1 = string1 + text[string_Length];  
  33.                     string_Length--;  
  34.                 }  
  35.             }  
  36.   
  37.             int j = string1.Length - 1;  
  38.             while (j >= 0)  
  39.             {  
  40.                 string3 = string3 + string1[j];  
  41.                 j--;  
  42.             }  
  43.   
  44.             Console.WriteLine("\nReverse String : {0}\n", string2 + string3);  
  45.         }  
  46.     }  
  47. }  

Enter the string to reverse :

Hello welcome to our website

Reverse String : website our to welcome Hello

Press any key to continue . . .