VelizarAvramov

04. Split by Word Casing

Dec 2nd, 2018
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.74 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3.  
  4. namespace _04._Split_by_Word_Casing
  5. {
  6.     class SplitByWord
  7.     {
  8.         static void Main(string[] args)
  9.         {
  10.             string[] words = Console.ReadLine()
  11.                 .Split(",;:.!()\"'\\/[] ".ToCharArray()
  12.                 ,StringSplitOptions.RemoveEmptyEntries);
  13.  
  14.             List<string> upperCase = new List<string>();
  15.             List<string> lowerCase = new List<string>();
  16.             List<string> mixed = new List<string>();
  17.  
  18.             foreach (var word in words)
  19.             {
  20.                 if (IsUpperWord(word))
  21.                 {
  22.                     upperCase.Add(word);
  23.                 }
  24.                 else if (IsLowerWord(word))
  25.                 {
  26.                     lowerCase.Add(word);
  27.                 }
  28.                 else
  29.                 {
  30.                     mixed.Add(word);
  31.                 }
  32.             }
  33.  
  34.             Console.WriteLine("Lower-case: {0}", string.Join(", ", lowerCase));
  35.             Console.WriteLine("Mixed-case: {0}", string.Join(", ", mixed));
  36.             Console.WriteLine("Upper-case: {0}", string.Join(", ", upperCase));
  37.  
  38.         }
  39.         static bool IsUpperWord(string word)
  40.         {
  41.             foreach (char symbol in word)
  42.             {
  43.                 if ('A' > symbol || symbol > 'Z')
  44.                 {
  45.                     return false;
  46.                 }              
  47.             }
  48.             return true;
  49.         }
  50.         static bool IsLowerWord(string word)
  51.         {
  52.             foreach (char symbol in word)
  53.             {
  54.                 if ('a' > symbol || symbol > 'z')
  55.                 {
  56.                     return false;
  57.                 }
  58.             }
  59.             return true;
  60.         }
  61.     }
  62. }
Advertisement
Add Comment
Please, Sign In to add comment