Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Linq;
- namespace _01._Email_Validator
- {
- class Program
- {
- static void Main(string[] args)
- {
- string email = Console.ReadLine();
- while (true)
- {
- string input = Console.ReadLine();
- if (input == "Complete")
- {
- break;
- }
- var tokens = input.Split().ToList();
- string command = tokens[0];
- switch (command)
- {
- case "Make":
- if (tokens[1] == "Upper")
- {
- email = email.ToUpper();
- Console.WriteLine(email);
- }
- else
- {
- email = email.ToLower();
- Console.WriteLine(email);
- }
- break;
- case "GetDomain":
- int count = int.Parse(tokens[1]);
- if (count <= email.Length)
- {
- int startIdex = email.Length - count;
- string subStr = email.Substring(startIdex);
- Console.WriteLine(subStr);
- }
- break;
- case "GetUsername":
- if (email.Contains("@"))
- {
- int index = int.Parse(email.IndexOf('@').ToString());
- int lenght = index - 0;
- string subStr = email.Substring(0, index);
- Console.WriteLine(subStr);
- }
- else
- {
- Console.WriteLine($"The email {email} doesn't contain the @ symbol.");
- }
- break;
- case "Replace":
- char ch = char.Parse(tokens[1]);
- if (email.Contains(ch))
- {
- email = email.Replace(ch, '-');
- Console.WriteLine(email);
- }
- break;
- case "Encrypt":
- var charArr = email.ToCharArray();
- foreach (var item in charArr)
- {
- Console.Write((int)item + " ");
- }
- Console.WriteLine();
- break;
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement