ellapt

T14.13.ReverseSentence

Feb 3rd, 2013
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.69 KB | None | 0 0
  1. using System;
  2. using System.Text;
  3.  
  4. class ReverseCentence
  5. {
  6. static void Main()
  7. {
  8. Console.WriteLine("Reverse the words in given sentence");
  9. string text = "C# is not C++, not PHP and not Delphi!";
  10. char[] pattern = new char[] { '.', '!', ',', ' ' };
  11. string[] words = text.Split(pattern, StringSplitOptions.RemoveEmptyEntries);
  12. Console.WriteLine("Original text:\n{0}", text);
  13. Console.WriteLine("Reversed sentence:");
  14. Array.Reverse(words);
  15. for (int i = 0; i < words.Length-1; i++)
  16. {
  17. Console.Write(words[i]+" ");
  18. }
  19. Console.WriteLine(words[words.Length-1]+text[text.Length-1]);
  20. }
  21. }
Advertisement
Add Comment
Please, Sign In to add comment