Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 01. Valid Usernames
- Write a program that reads user names on a single line (joined by ", ") and prints all valid usernames.
- A valid username is:
- • Has length between 3 and 16 characters
- • Contains only letters, numbers, hyphens and underscores
- Examples
- Input Output
- sh, too_long_username, !lleg@l ch@rs, jeffbutt jeffbutt
- Jeff, john45, ab, cd, peter-ivanov, @smith Jeff
- John45
- peter-ivanov
- using System;
- namespace ExamResults
- {
- class Program
- {
- static void Main(string[] args)
- {
- var userNames = Console.ReadLine().Split(", ");
- foreach (var userName in userNames)
- {
- if (userName.Length >= 3 && userName.Length <= 16)
- {
- var counter = 0;
- foreach (var symbol in userName)
- {
- if (!(Char.IsLetterOrDigit(symbol) || symbol == '-' || userName.Contains('_')))
- {
- break;
- }
- else
- {
- counter++;
- }
- }
- if (counter == userName.Length)
- {
- Console.WriteLine(userName);
- }
- }
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment