Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace _01_ValidUsernames
- {
- class Program
- {
- static void Main(string[] args)
- {
- string[] usernames = Console.ReadLine().Split(", ");
- for (int i = 0; i < usernames.Length; i++)
- {
- string currentUserName = usernames[i];
- bool isWithRightLength = IsWithRightLenth(currentUserName);
- bool isWithRightContent = IsContainingRightSymbols(currentUserName);
- if (isWithRightLength && isWithRightContent)
- {
- Console.WriteLine(currentUserName);
- }
- }
- }
- static bool IsContainingRightSymbols(string currentUserName)
- {
- char[] usernameArray = currentUserName.ToCharArray();
- foreach (var letter in usernameArray)
- {
- if (!Char.IsLetterOrDigit(letter) && letter != '-' && letter != '_')
- {
- return false;
- }
- }
- return true;
- }
- static bool IsWithRightLenth(string currentUserName)
- {
- int length = currentUserName.Length;
- if (3 <= length && length <= 16)
- {
- return true;
- }
- return false;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement