Advertisement
svephoto

String Manipulator - 2

Nov 17th, 2019
227
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.01 KB | None | 0 0
  1. using System;
  2.  
  3. namespace StringManipulator2
  4. {
  5. class Program
  6. {
  7. static void Main(string[] args)
  8. {
  9. string text = Console.ReadLine();
  10. string command = Console.ReadLine();
  11.  
  12. while (command != "Done")
  13. {
  14. string[] token = command.Split();
  15.  
  16. if (token[0] == "Change")
  17. {
  18. text = text.Replace(token[1], token[2]);
  19. Console.WriteLine(text);
  20. }
  21. else if (token[0] == "Includes")
  22. {
  23. if (text.Contains(token[1]))
  24. {
  25. Console.WriteLine("True");
  26. }
  27. else
  28. {
  29. Console.WriteLine("False");
  30. }
  31. }
  32. else if (token[0] == "End")
  33. {
  34. string findString = token[1];
  35. if (text.EndsWith(findString))
  36. {
  37. Console.WriteLine("True");
  38. }
  39. else
  40. {
  41. Console.WriteLine("False");
  42. }
  43. }
  44. else if (token[0] == "Uppercase")
  45. {
  46. text = text.ToUpper();
  47. Console.WriteLine(text);
  48. }
  49. else if (token[0] == "FindIndex")
  50. {
  51. int index = text.IndexOf(token[1]);
  52. Console.WriteLine(index);
  53. }
  54. else if (token[0] == "Cut")
  55. {
  56. int startIndex = int.Parse(token[1]);
  57. int length = int.Parse(token[2]);
  58. text = text.Substring(startIndex, length);
  59. Console.WriteLine(text);
  60. }
  61.  
  62. command = Console.ReadLine();
  63. }
  64. }
  65. }
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement