vaakata

Split by Word Casing

May 26th, 2016
386
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.43 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 SplitWordCas_24._05._2016
  8. {
  9.     class Program
  10.     {
  11.        
  12.         static void Main(string[] args)
  13.         {
  14.             char[] separators = { ',', ';', ':', '.', '!', ' ' };
  15.  
  16.             List<string> words = Console.ReadLine().Split(separators, StringSplitOptions.RemoveEmptyEntries).ToList();
  17.  
  18.             List<string> lowerCaseWords = IsLowerCase(separators, words);
  19.             List<string> upperCaseWords = IsUpperCase(separators, words);
  20.             List<string> mixedCaseWords = IsMixedCase(separators, words);    
  21.  
  22.             Console.WriteLine("Lower-case: {0}", string.Join(", ", lowerCaseWords));
  23.             Console.WriteLine("Mixed-case: {0}", string.Join(", ", mixedCaseWords));
  24.             Console.WriteLine("Upper-case: {0}", string.Join(", ", upperCaseWords));            
  25.         }
  26.  
  27.         static List<string> IsMixedCase(char[] separators, List<string> words)
  28.         {
  29.             List<string> mixedCaseWords = new List<string>();
  30.  
  31.             foreach (string word in words)
  32.             {
  33.                 int upperCaseLetters = 0;
  34.                 int lowerCaseLetters = 0;
  35.                 foreach (char letter in word)
  36.                 {
  37.                     if (char.IsUpper(letter))
  38.                     {
  39.                         upperCaseLetters++;
  40.                     }
  41.                     else if (char.IsLower(letter))
  42.                     {
  43.                         lowerCaseLetters++;
  44.                     }
  45.                 }
  46.                 if (upperCaseLetters != word.Length && lowerCaseLetters != word.Length)
  47.                 {
  48.                     mixedCaseWords.Add(word);
  49.                 }
  50.             }
  51.             return mixedCaseWords;
  52.         }
  53.         static List<string> IsUpperCase(char[] separators, List<string> words)
  54.         {
  55.             List<string> upperCaseWords = new List<string>();
  56.  
  57.             foreach(string word in words)
  58.             {
  59.                 int upperCaseLetters = 0;
  60.                 foreach (char letter in word)
  61.                 {
  62.                     if (char.IsUpper(letter))
  63.                     {
  64.                         upperCaseLetters++;
  65.                     }
  66.                     else if (char.IsLower(letter))
  67.                     {
  68.                         break;
  69.                     }
  70.                 }
  71.                 if (upperCaseLetters == word.Length)
  72.                 {
  73.                     upperCaseWords.Add(word);
  74.                 }
  75.             }
  76.             return upperCaseWords;
  77.  
  78.         }
  79.         static List<string> IsLowerCase(char[] separators, List<string> words)
  80.         {            
  81.             List<string> lowerCaseWords = new List<string>();
  82.  
  83.             foreach (string word in words)
  84.             {
  85.                 int lowerCaseLetters = 0;
  86.                 foreach (char letter in word)
  87.                 {
  88.                     if (char.IsLower(letter))
  89.                     {
  90.                         lowerCaseLetters++;
  91.                     }
  92.                     else if (char.IsUpper(letter))
  93.                     {
  94.                         break;
  95.                     }
  96.                 }
  97.                 if (lowerCaseLetters== word.Length)
  98.                 {
  99.                     lowerCaseWords.Add(word);
  100.                 }
  101.             }
  102.             return lowerCaseWords;      
  103.         }
  104.     }
  105. }
Advertisement
Add Comment
Please, Sign In to add comment