Advertisement
Guest User

Username

a guest
Mar 28th, 2020
200
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.65 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3.  
  4. namespace Username
  5. {
  6. class Program
  7. {
  8. static void Main(string[] args)
  9. {
  10. string text = Console.ReadLine();
  11. string command = Console.ReadLine();
  12.  
  13. while (command != "Sign up")
  14. {
  15. string[] token = command.Split();
  16. if(token[0] == "Case")
  17. {
  18. if(token[1] == "lower")
  19. {
  20. text = text.ToLower();
  21. Console.WriteLine(text);
  22. }
  23. if (token[1] == "upper")
  24. {
  25. text = text.ToUpper();
  26. Console.WriteLine();
  27. }
  28. }
  29. else if(token[0] == "Reverse")
  30. {
  31. int startIndex = int.Parse(token[1]);
  32. int endIndex = int.Parse(token[2]);
  33. // !!!
  34. if(startIndex >= 0 && endIndex > startIndex && endIndex < text.Length)
  35. {
  36. int length = endIndex - startIndex +1 ;
  37. string word = text.Substring(startIndex, length);
  38. Console.WriteLine(String.Join("",word.Reverse()));
  39. }
  40.  
  41. }
  42. else if(token[0]== "Cut")
  43. {
  44. string check = token[1];
  45.  
  46. if (text.Contains(check))
  47. {
  48. text = text.Remove(text.IndexOf(check), check.Length);
  49. Console.WriteLine(text);
  50. }
  51. else
  52. {
  53. Console.WriteLine($"The word {text} doesn't contain {check}.");
  54. }
  55. }
  56. else if(token[0] == "Replace")
  57. {
  58. char currChar = char.Parse(token[1]);
  59. text = text.Replace(currChar, '*');
  60. Console.WriteLine(text);
  61. }
  62. else if(token[0] == "Check")
  63. {
  64. char charToCheck = char.Parse(token[1]);
  65. if (text.Contains(charToCheck))
  66. {
  67. Console.WriteLine("Valid");
  68. }
  69. else
  70. {
  71. Console.WriteLine($"Your username must contain {charToCheck}.");
  72. }
  73. }
  74. command = Console.ReadLine();
  75. }
  76.  
  77. }
  78. }
  79. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement