Advertisement
desislava_topuzakova

03

Mar 31st, 2024
35
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.76 KB | None | 0 0
  1. using System;
  2.  
  3. public class P01ValidUsernames {
  4. public static void Main(string[] args) {
  5. string[] usernamesArr = Console.ReadLine().Split(", ");
  6.  
  7. foreach (string username in usernamesArr) {
  8. if (IsValidUsername(username)) {
  9. Console.WriteLine(username);
  10. }
  11. }
  12. }
  13.  
  14. private static bool IsValidUsername(string username) {
  15. bool isValidLength = username.Length >= 3 && username.Length <= 16;
  16. bool isValidSymbol = true;
  17. foreach (char ch in username) {
  18. if (!char.IsLetterOrDigit(ch) && ch != '-' && ch != '_') {
  19. isValidSymbol = false;
  20. break;
  21. }
  22. }
  23. return isValidLength && isValidSymbol;
  24. }
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement