Advertisement
WindFell

Split By Word Casing

Feb 25th, 2018
355
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.43 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. class SplitByWordCasing
  6. {
  7.     static void Main(string[] args)
  8.     {
  9.         List<string> words = Console.ReadLine()
  10.             .Split(",;:.!()\"'\\/[] ".ToCharArray(), StringSplitOptions.RemoveEmptyEntries)
  11.             .ToList();
  12.  
  13.         List<string> upperCase = new List<string>();
  14.         List<string> lowerCase = new List<string>();
  15.         List<string> mixedCase = new List<string>();
  16.  
  17.         foreach (string word in words)
  18.         {
  19.             switch (GetWordCasetype(word))
  20.             {
  21.                 case "upper":
  22.                     upperCase.Add(word);
  23.                     break;
  24.                 case "lower":
  25.                     lowerCase.Add(word);
  26.                     break;
  27.                 case "mixed":
  28.                     mixedCase.Add(word);
  29.                     break;
  30.             }
  31.         }
  32.  
  33.         Console.WriteLine("Lower-case: {0}", string.Join(", ", lowerCase));
  34.         Console.WriteLine("Mixed-case: {0}", string.Join(", ", mixedCase));
  35.         Console.WriteLine("Upper-case: {0}", string.Join(", ", upperCase));
  36.     }
  37.  
  38.     static string GetWordCasetype(string word)
  39.     {
  40.         string result = "mixed";
  41.  
  42.         if (word.All(char.IsLower))
  43.         {
  44.             result = "lower";
  45.         }
  46.         else if (word.All(char.IsUpper))
  47.         {
  48.             result = "upper";
  49.         }
  50.  
  51.         return result;
  52.     }
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement