Advertisement
knoteva

01. Valid Usernames

Jul 19th, 2019
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.79 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text.RegularExpressions;
  5.  
  6. namespace _01._Valid_Usernames
  7. {
  8.     class Program
  9.     {
  10.         static void Main(string[] args)
  11.         {
  12.  
  13.             string[] names = Console.ReadLine()
  14.                 .Split(", ")
  15.                 .ToArray();
  16.             List<string> validNames = new List<string>();
  17.  
  18.             for (int i = 0; i < names.Length; i++)
  19.             {
  20.                 if (names[i].Length >= 3 && names[i].Length <= 16 && names[i].All(c => Char.IsLetterOrDigit(c) || c.Equals('_') || c.Equals('-')))
  21.                 {
  22.                     validNames.Add(names[i]);
  23.                 }
  24.             }
  25.             Console.WriteLine(string.Join(Environment.NewLine, validNames));
  26.         }
  27.     }
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement