Advertisement
onqkoie

Untitled

Mar 19th, 2020
808
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.83 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3.  
  4. namespace _01._Email_Validator
  5. {
  6. class Program
  7. {
  8. static void Main(string[] args)
  9. {
  10. string email = Console.ReadLine();
  11.  
  12. while (true)
  13. {
  14. string input = Console.ReadLine();
  15.  
  16. if (input == "Complete")
  17. {
  18. break;
  19. }
  20.  
  21. var tokens = input.Split().ToList();
  22. string command = tokens[0];
  23.  
  24. switch (command)
  25. {
  26. case "Make":
  27. if (tokens[1] == "Upper")
  28. {
  29. email = email.ToUpper();
  30. Console.WriteLine(email);
  31. }
  32. else
  33. {
  34. email = email.ToLower();
  35. Console.WriteLine(email);
  36. }
  37.  
  38. break;
  39. case "GetDomain":
  40. int count = int.Parse(tokens[1]);
  41. if (count <= email.Length)
  42. {
  43. int startIdex = email.Length - count;
  44. string subStr = email.Substring(startIdex);
  45. Console.WriteLine(subStr);
  46. }
  47.  
  48. break;
  49.  
  50. case "GetUsername":
  51. if (email.Contains("@"))
  52. {
  53. int index = int.Parse(email.IndexOf('@').ToString());
  54. int lenght = index - 0;
  55. string subStr = email.Substring(0, index);
  56. Console.WriteLine(subStr);
  57. }
  58. else
  59. {
  60. Console.WriteLine($"The email {email} doesn't contain the @ symbol.");
  61. }
  62.  
  63.  
  64. break;
  65.  
  66. case "Replace":
  67. char ch = char.Parse(tokens[1]);
  68. if (email.Contains(ch))
  69. {
  70. email = email.Replace(ch, '-');
  71. Console.WriteLine(email);
  72. }
  73. break;
  74.  
  75. case "Encrypt":
  76. var charArr = email.ToCharArray();
  77. foreach (var item in charArr)
  78. {
  79. Console.Write((int)item + " ");
  80. }
  81. Console.WriteLine();
  82.  
  83. break;
  84. }
  85. }
  86. }
  87. }
  88. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement