ivan_gy6ev

Split by Word Casing

Jun 16th, 2017
171
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.19 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 _04.Split_by_Word_Casing
  8. {
  9. class Program
  10. {
  11. static void Main(string[] args)
  12. {
  13. List<string> inputText = Console.ReadLine()
  14. .Split(new char[] { ',', ';', ':', '.', '!', '(', ')',
  15. '"', '\\', '/', '[', ']', ' ' },
  16. StringSplitOptions.RemoveEmptyEntries)
  17. .ToList();
  18. List<string> lowerCase = new List<string>();
  19. List<string> upperCase = new List<string>();
  20. List<string> mixedCase = new List<string>();
  21. for(int i =0; i<inputText.Count; i++)
  22. {
  23. string result =GetData(inputText[i]);
  24. switch (result)
  25. {
  26. case "lower": lowerCase.Add(inputText[i]); break;
  27. case "upper": upperCase.Add(inputText[i]); break;
  28. case "mixed": mixedCase.Add(inputText[i]); break;
  29. }
  30. }
  31. Console.WriteLine("Lower-case: {0}",string.Join(", ", lowerCase));
  32. Console.WriteLine("Mixed-case: {0}",string.Join(", ", mixedCase));
  33. Console.WriteLine("Upper-case: {0}", string.Join(", ", upperCase));
  34. }
  35.  
  36. private static string GetData(string element)
  37. {
  38. string typeIs = string.Empty;
  39. if (element[0]>='a' && element[0] <= 'z') typeIs="lower";
  40. else if (element[0]>='A' && element[0] <= 'Z') typeIs="upper";
  41. else typeIs="mixed";
  42. for (int i=1; i<element.Length; i++)
  43. {
  44. if (element[i] >= 'a' && element[i] <= 'z'
  45. && typeIs == "lower") typeIs = "lower";
  46. else if (element[i] >= 'A' && element[i] <= 'Z'
  47. && typeIs == "upper") typeIs = "upper";
  48. else
  49. {
  50. typeIs = "mixed";
  51. break;
  52. }
  53. }
  54. return typeIs;
  55. }
  56. }
  57. }
Advertisement
Add Comment
Please, Sign In to add comment