ellapt

T14.24.PrintWordsAlphabetically

Feb 3rd, 2013
38
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.76 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text.RegularExpressions;
  4.  
  5. class PrintWordsAlphabetically
  6. {
  7. static void Main()
  8. {
  9. Console.WriteLine("Read words, separated by spaces, print the list in an alphabetical order.\n");
  10.  
  11. string text = "The low-cost computers on integrated circuits has transformed modern society.";
  12. Console.WriteLine("The original text is:\n{0}\n\nThe result is:\n", text);
  13.  
  14. var words = new List<string>();
  15.  
  16. foreach (Match item in Regex.Matches(text, @"\w+"))
  17. {
  18. words.Add(item.Value);
  19. }
  20.  
  21. words.Sort();
  22.  
  23. foreach (string item in words)
  24. {
  25. Console.WriteLine(item);
  26. }
  27. Console.WriteLine();
  28. }
  29. }
Advertisement
Add Comment
Please, Sign In to add comment