- namespace Reverse
- {
- using System;
- public class StringReverse
- {
- public static void Main(string[] args)
- {
- Console.WriteLine("Enter the string to reverse : \n");
- string text = Console.ReadLine();
- int string_Length = text.Length - 1;
- string string1 = string.Empty;
- string string2 = string.Empty;
- string string3 = string.Empty;
- while (string_Length >= 0)
- {
-
- if (text[string_Length].Equals(' '))
- {
- int i = string1.Length - 1;
- while (i >= 0)
- {
- string2 = string2 + string1[i];
- i--;
- }
-
- string1 = string.Empty;
- string2 = string2 + ' ';
- string_Length--;
- }
- else
- {
- string1 = string1 + text[string_Length];
- string_Length--;
- }
- }
-
- int j = string1.Length - 1;
- while (j >= 0)
- {
- string3 = string3 + string1[j];
- j--;
- }
-
- Console.WriteLine("\nReverse String : {0}\n", string2 + string3);
- }
- }
- }
Enter the string to reverse :
Hello welcome to our website
Reverse String : website our to welcome Hello
Press any key to continue . . .