Advertisement
Guest User

Lab13SplitByWordCasing

a guest
Oct 9th, 2016
168
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.18 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace Lab13SplitByWordCasing
  6. {
  7.     public class Lab13SplitByWordCasing
  8.     {
  9.         public static void Main()
  10.         {
  11.             char[] separators = new char[] { ',', ';', ':', '.', '!', '(', ')', '"', '\'', '\\', '/', '[', ']', ' ' };
  12.  
  13.             List<string> input = Console.ReadLine().Split(separators, StringSplitOptions.RemoveEmptyEntries).ToList();
  14.  
  15.  
  16.             List<string> lowerCaseList = new List<string>();
  17.             List<string> upperCaseList = new List<string>();
  18.             List<string> mixedCaseList = new List<string>();
  19.  
  20.  
  21.             foreach (var w in input)
  22.             {
  23.                 var type = GetWordType(w);
  24.  
  25.                 if (type == WordType.UpperCase)
  26.                 {
  27.                     upperCaseList.Add(w);
  28.                 }
  29.                 else if (type == WordType.LowerCase)
  30.                 {
  31.                     lowerCaseList.Add(w);
  32.                 }
  33.                 else if (type == WordType.MixedCase)
  34.                 {
  35.                     mixedCaseList.Add(w);
  36.                 }
  37.             }
  38.  
  39.             Console.WriteLine("Lower-case: " + String.Join(", ", lowerCaseList));
  40.             Console.WriteLine("Mixed-case: " + String.Join(", ", mixedCaseList));
  41.             Console.WriteLine("Upper-case: " + String.Join(", ", upperCaseList));
  42.  
  43.         }
  44.  
  45.         enum WordType { UpperCase, MixedCase, LowerCase };
  46.  
  47.  
  48.         private static WordType GetWordType(string word)
  49.         {
  50.             var lowerLetters = 0;
  51.             var upperLetters = 0;
  52.             foreach (var l in word)
  53.             {
  54.                 if (char.IsUpper(l))
  55.                 {
  56.                     upperLetters++;
  57.                 }
  58.                 else if (char.IsLower(l))
  59.                 {
  60.                     lowerLetters++;
  61.                 }
  62.             }
  63.  
  64.             if (upperLetters == word.Length)
  65.             {
  66.                 return WordType.UpperCase;
  67.             }
  68.             if (lowerLetters == word.Length)
  69.             {
  70.                 return WordType.LowerCase;
  71.             }
  72.  
  73.             return WordType.MixedCase;
  74.  
  75.         }
  76.  
  77.     }
  78. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement