Advertisement
VickSuna

Untitled

Aug 14th, 2021
30
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.94 KB | None | 0 0
  1. using System;
  2.  
  3. namespace FFE
  4. {
  5. class Program
  6. {
  7. static void Main(string[] args)
  8. {
  9. string input = Console.ReadLine();
  10.  
  11. string command = Console.ReadLine();
  12.  
  13. while (command != "Finish")
  14. {
  15. string[] splitted = command.Split();
  16.  
  17. if (command.Contains("Replace"))
  18. {
  19. string currentString = (splitted[1]);
  20. string newString = (splitted[2]);
  21.  
  22. input = input.Replace(currentString, newString);
  23.  
  24. Console.WriteLine(input);
  25. }
  26. else if (command.Contains("Cut"))
  27. {
  28. int startIndex = int.Parse(splitted[1]);
  29. int endIndex = int.Parse(splitted[2]);
  30.  
  31. if (startIndex >= 0 && endIndex < input.Length)
  32. {
  33. input = input.Remove(startIndex, endIndex - startIndex + 1);
  34.  
  35. Console.WriteLine(input);
  36. }
  37. else
  38. {
  39. Console.WriteLine("Invalid indexes!");
  40. }
  41.  
  42. }
  43. else if (command.Contains("Upper"))
  44. {
  45. input = input.ToUpper();
  46.  
  47. Console.WriteLine(input);
  48. }
  49. else if (command.Contains("Lower"))
  50. {
  51. input = input.ToLower();
  52.  
  53. Console.WriteLine(input);
  54. }
  55. else if (command.Contains("Check"))
  56. {
  57. string toCheck = splitted[1];
  58.  
  59. if (input.Contains(toCheck))
  60. {
  61. Console.WriteLine($"Message contains {toCheck}");
  62. }
  63. else
  64. {
  65. Console.WriteLine($"Message doesn't contain {toCheck}");
  66. }
  67.  
  68. }
  69. else if (command.Contains("Sum"))
  70. {
  71. int startIndex = int.Parse(splitted[1]);
  72. int endIndex = int.Parse(splitted[2]);
  73.  
  74. if (startIndex >= 0 && endIndex < input.Length)
  75. {
  76. string toSum = input.Substring(startIndex, endIndex - startIndex + 1);
  77.  
  78. int sum = 0;
  79.  
  80. for (int i = 0; i < toSum.Length; i++)
  81. {
  82.  
  83. sum += toSum[i];
  84.  
  85. }
  86.  
  87. Console.WriteLine(sum);
  88. }
  89. else
  90. {
  91. Console.WriteLine("Invalid indexes!");
  92. }
  93.  
  94.  
  95. }
  96.  
  97. command = Console.ReadLine();
  98. }
  99. }
  100. }
  101. }
  102.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement