Advertisement
petarkobakov

String Manipulator Group 1

Aug 6th, 2020 (edited)
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.19 KB | None | 0 0
  1.  
  2. using System;
  3. using System.Text;
  4.  
  5. namespace String_Manipulator___Group_1
  6. {
  7. class Program
  8. {
  9. static void Main(string[] args)
  10. {
  11. string theString = Console.ReadLine();
  12.  
  13. while (true)
  14. {
  15. string[] commands = Console.ReadLine().Split();
  16.  
  17. if (commands[0] == "End")
  18. {
  19. break;
  20. }
  21.  
  22. else if (commands[0] == "Translate")
  23. {
  24. char toReplace = char.Parse(commands[1]);
  25. char replacement =char.Parse(commands[2]);
  26.  
  27. if (theString.Contains(toReplace))
  28. {
  29. theString = theString.Replace(toReplace,replacement);
  30.  
  31. Console.WriteLine(theString);
  32. }
  33. }
  34.  
  35. else if (commands[0] == "Includes")
  36. {
  37. string toCheck = commands[1];
  38. bool contains = true;
  39.  
  40. if (theString.Contains(toCheck))
  41. {
  42. Console.WriteLine(contains);
  43. }
  44.  
  45. else
  46. {
  47. Console.WriteLine(!contains);
  48. }
  49. }
  50.  
  51. else if (commands[0] == "Start")
  52. {
  53. string toCheck = commands[1];
  54. StringBuilder test = new StringBuilder();
  55.  
  56. for (int i = 0; i < toCheck.Length; i++)
  57. {
  58. test.Append(theString[i]);
  59. }
  60.  
  61. if (test.Equals(toCheck))
  62. {
  63. Console.WriteLine("True");
  64. }
  65.  
  66. else
  67. {
  68. Console.WriteLine("False");
  69. }
  70.  
  71. }
  72.  
  73. else if (commands[0] == "Lowercase")
  74. {
  75. theString = theString.ToLower();
  76.  
  77. Console.WriteLine(theString);
  78. }
  79.  
  80. else if (commands[0] == "FindIndex")
  81. {
  82. char index = char.Parse(commands[1]);
  83.  
  84. if (theString.Contains(index))
  85. {
  86. for (int i = theString.Length-1; i >= 0; i--)
  87. {
  88. char test = theString[i];
  89. if (test.Equals(index))
  90. {
  91. Console.WriteLine(i);
  92. break;
  93. }
  94. }
  95. }
  96.  
  97. }
  98.  
  99. else if (commands[0] == "Remove")
  100. {
  101. int startIndex = int.Parse(commands[1]);
  102. int count = int.Parse(commands[2]);
  103.  
  104. theString = theString.Remove(startIndex, count);
  105.  
  106. Console.WriteLine(theString);
  107. }
  108. }
  109. }
  110. }
  111. }
  112.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement