kirililchev3

Split by Word Casing/ Lists, Arrays

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