Advertisement
Guest User

Untitled

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