Advertisement
Mitax

Capitalize_Words

Apr 5th, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.58 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace _5.Capitalize_Words
  8. {
  9. class CapitalizeWords
  10. {
  11. static void Main(string[] args)
  12. {
  13. var line = Console.ReadLine();
  14. StringBuilder words = new StringBuilder();
  15.  
  16. while (line != "end")
  17. {
  18. string[] inputParams = line.Split(new[] { '.', '-', ',', '!', '?', ';', ':', ' ' }, StringSplitOptions.RemoveEmptyEntries);
  19.  
  20. foreach (var word in inputParams)
  21. {
  22. for (int i = 0; i < word.Length; i++)
  23. {
  24. if (i == 0)
  25. {
  26. words.Append(word[i].ToString().ToUpper());
  27. }
  28. else
  29. {
  30. words.Append(word[i].ToString().ToLower());
  31. }
  32. if (i == word.Length - 1)
  33. {
  34. words.Append(", "); //adding ", " after each word
  35. }
  36. }
  37. }
  38. var builderLength = words.Length - 2;
  39. words = words.Remove(builderLength, 1); //removing ", " from the end of each sentence
  40. words.Append("\n"); //adding new Line after each sentece
  41.  
  42. line = Console.ReadLine();
  43. }
  44. Console.WriteLine(words);
  45. }
  46. }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement