Advertisement
ralitsa_d

04. Split by Word Casing

Sep 3rd, 2016
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.91 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 SplitByWordCasing
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             char[] separators = new char[] { ',', ';', ':', '.', '!', '(', ')', '\'', '\'', '\\', '/', '[', ']', ' ' };
  14.             List<string> words = Console.ReadLine()
  15.                 .Split(separators, StringSplitOptions.RemoveEmptyEntries)
  16.                 .ToList();
  17.  
  18.             List<string> lowerCase = new List<string>();
  19.             List<string> upperCase = new List<string>();
  20.             List<string> mixedCase = new List<string>();
  21.  
  22.             foreach (var word in words)
  23.             {
  24.                 if (isLower(word))
  25.                 {
  26.                     lowerCase.Add(word);
  27.                 }
  28.                 else if (isUpper(word))
  29.                 {
  30.                     upperCase.Add(word);
  31.                 }
  32.                 else
  33.                 {
  34.                     mixedCase.Add(word);
  35.                 }
  36.             }
  37.  
  38.             Console.WriteLine("Lower-case: " + string.Join(", ", lowerCase));
  39.             Console.WriteLine("Mixed-case: " + string.Join(", ", mixedCase));
  40.             Console.WriteLine("Upper-case: " + string.Join(", ", upperCase));
  41.         }
  42.  
  43.         public static bool isLower(string word)
  44.         {
  45.             foreach (var letter in word)
  46.             {
  47.                 if (!Char.IsLower(letter))
  48.                 {
  49.                     return false;
  50.                 }
  51.             }
  52.             return true;
  53.         }
  54.  
  55.         public static bool isUpper(string word)
  56.         {
  57.             foreach (var letter in word)
  58.             {
  59.                 if (!Char.IsUpper(letter))
  60.                 {
  61.                     return false;
  62.                 }
  63.             }
  64.             return true;
  65.         }
  66.     }
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement