Advertisement
petyaminkova91

Untitled

Nov 16th, 2019
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.35 KB | None | 0 0
  1. using System;
  2.  
  3. namespace _01_ValidUsernames
  4. {
  5. class Program
  6. {
  7. static void Main(string[] args)
  8. {
  9. string[] usernames = Console.ReadLine().Split(", ");
  10.  
  11. for (int i = 0; i < usernames.Length; i++)
  12. {
  13. string currentUserName = usernames[i];
  14.  
  15. bool isWithRightLength = IsWithRightLenth(currentUserName);
  16. bool isWithRightContent = IsContainingRightSymbols(currentUserName);
  17.  
  18. if (isWithRightLength && isWithRightContent)
  19. {
  20. Console.WriteLine(currentUserName);
  21. }
  22. }
  23.  
  24. }
  25.  
  26. static bool IsContainingRightSymbols(string currentUserName)
  27. {
  28. char[] usernameArray = currentUserName.ToCharArray();
  29.  
  30. foreach (var letter in usernameArray)
  31. {
  32. if (!Char.IsLetterOrDigit(letter) && letter != '-' && letter != '_')
  33. {
  34. return false;
  35. }
  36. }
  37.  
  38. return true;
  39. }
  40.  
  41. static bool IsWithRightLenth(string currentUserName)
  42. {
  43. int length = currentUserName.Length;
  44.  
  45. if (3 <= length && length <= 16)
  46. {
  47. return true;
  48. }
  49.  
  50. return false;
  51. }
  52. }
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement