petarkobakov

Username

Aug 7th, 2020 (edited)
171
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.36 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Linq.Expressions;
  5. using System.Text;
  6.  
  7. namespace Username
  8. {
  9. class Program
  10. {
  11. static void Main(string[] args)
  12. {
  13.  
  14. string input = Console.ReadLine();
  15. string command = Console.ReadLine();
  16.  
  17.  
  18. while (command!= "Sign up")
  19. {
  20. string[] element = command.Split();
  21. string operation = element[0];
  22.  
  23.  
  24. switch (operation)
  25. {
  26. case "Case":
  27. if (element[1] == "lower")
  28. {
  29. input = input.ToLower();
  30. Console.WriteLine(input);
  31. }
  32. else if (element[1] == "upper")
  33. {
  34. input = input.ToUpper();
  35. Console.WriteLine(input);
  36. }
  37. break;
  38.  
  39. case "Reverse":
  40. int startIndex = int.Parse(element[1]);
  41. int endIndex = int.Parse(element[2]);
  42. StringBuilder test = new StringBuilder();
  43.  
  44. if (startIndex>=0 && endIndex<=input.Length)
  45. {
  46. for (int i = startIndex; i <= endIndex; i++)
  47. {
  48. test.Append(input[i]);
  49. }
  50.  
  51. List<char> result = test.ToString().ToCharArray().Reverse().ToList();
  52.  
  53. Console.WriteLine(string.Join( "", result));
  54. }
  55. break;
  56.  
  57. case "Cut":
  58. string substring = element[1];
  59.  
  60. if (!input.Contains(substring))
  61. {
  62. Console.WriteLine($"The word {input} doesn't contain {substring}.");
  63. }
  64.  
  65. else
  66. {
  67. int index = input.IndexOf(substring);
  68. input = input.Remove(index, substring.Length);
  69. Console.WriteLine(input);
  70.  
  71. }
  72. break;
  73.  
  74. case "Replace":
  75. char symbol = char.Parse(element[1]);
  76.  
  77. if (input.Contains(symbol))
  78. {
  79. input = input.Replace(symbol, '*');
  80. Console.WriteLine(input);
  81. }
  82. break;
  83.  
  84. case "Check":
  85.  
  86. char validation = char.Parse(element[1]);
  87.  
  88. if (input.Contains(validation))
  89. {
  90. Console.WriteLine("Valid");
  91. }
  92.  
  93. else
  94. {
  95. Console.WriteLine($"Your username must contain {validation}.");
  96. }
  97. break;
  98. }
  99.  
  100.  
  101. command = Console.ReadLine();
  102. }
  103. }
  104. }
  105. }
  106.  
Advertisement
Add Comment
Please, Sign In to add comment