Advertisement
grubcho

Split by word casing - Lists

Jun 23rd, 2017
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.89 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. //Read a text, split it into words and distribute them into 3 lists.
  7. //Lower-case words like “programming”, “at” and “databases” – consist of lowercase letters only.
  8. //Upper-case words like “PHP”, “JS” and “SQL” – consist of uppercase letters only.
  9. //Mixed-case words like “C#”, “SoftUni” and “Java” – all others.
  10. //Use the following separators between the words: , ; : . ! ( ) " ' \ / [ ] space
  11. //print the 3 lists as shown in the example below.
  12.  
  13. namespace Split_by_Word_Casing___Lists
  14. {
  15.     class Program
  16.     {
  17.         static void Main(string[] args)
  18.         {
  19.             char[] delimiters = ",;:.!()\"\'\\/[] ".ToCharArray();
  20.             List <string> text = Console.ReadLine().Split(delimiters, StringSplitOptions.RemoveEmptyEntries).ToList();
  21.             List<string> lowerCase = new List<string>();
  22.             List<string> upperCase = new List<string>();
  23.             List<string> mixedCase = new List<string>();
  24.             foreach (var word in text)
  25.             {
  26.                 if (word.Any(x => !char.IsLetter(x)))
  27.                 {
  28.                     mixedCase.Add(word);
  29.                 }
  30.                 else if (word.ToLower().Equals(word))
  31.                 {
  32.                     lowerCase.Add(word);
  33.                 }
  34.                 else if (word.ToUpper().Equals(word))
  35.                 {
  36.                     upperCase.Add(word);
  37.                 }
  38.                 else
  39.                 {
  40.                     mixedCase.Add(word);
  41.                 }
  42.             }
  43.             Console.WriteLine("Lower-case: " + string.Join(", ", lowerCase));
  44.             Console.WriteLine("Mixed-case: " + string.Join(", ", mixedCase));
  45.             Console.WriteLine("Upper-case: " + string.Join(", ", upperCase));
  46.         }
  47.     }
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement