Advertisement
Guest User

String Manipulator

a guest
Dec 6th, 2019
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.81 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3.  
  4. namespace _01G2August
  5. {
  6. class Program
  7. {
  8. static void Main(string[] args)
  9. {
  10. string input = Console.ReadLine();
  11.  
  12.  
  13.  
  14. while (true)
  15. {
  16. string commands = Console.ReadLine();
  17. string[] cmd = commands.Split(" ");
  18. string cmdType = cmd[0];
  19. if(cmdType == "Done")
  20. {
  21. break;
  22. }
  23. if(cmdType == "Change")
  24. {
  25. string ch = cmd[1];
  26. string replacement = cmd[2];
  27.  
  28. input = input.Replace(ch,replacement);
  29. Console.WriteLine(input);
  30. }
  31. if(cmdType == "Includes")
  32. {
  33. bool valid = input.Contains(cmd[1]);
  34. Console.WriteLine(valid);
  35. }
  36. if(cmdType == "End")
  37. {
  38. bool end = input.EndsWith(cmd[1]);
  39. Console.WriteLine(end);
  40. }
  41. if(cmdType == "Uppercase")
  42. {
  43. input = input.ToUpper();
  44. Console.WriteLine(input);
  45. }
  46. if(cmdType == "FindIndex")
  47. {
  48. int indexOf = input.IndexOf(cmd[1]);
  49. Console.WriteLine(indexOf);
  50. }
  51. if(cmdType == "Cut")
  52. {
  53. int startIndex = int.Parse(cmd[1]);
  54. int count = int.Parse(cmd[2]);
  55. string removedString = input.Substring(startIndex,count);
  56. Console.WriteLine(removedString);
  57. }
  58. }
  59. }
  60. }
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement