Advertisement
Guest User

Untitled

a guest
Aug 11th, 2020
409
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.83 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Reflection.Metadata.Ecma335;
  5. using System.Text;
  6. using System.Text.RegularExpressions;
  7.  
  8.  
  9. class Program
  10. {
  11. static void Main()
  12. {
  13. string message = Console.ReadLine();
  14. string input;
  15. while ((input = Console.ReadLine()) != "Reveal")
  16. {
  17. string[] tokens = input.Split(":|:", StringSplitOptions.RemoveEmptyEntries);
  18. string command = tokens[0];
  19. if (command == "InsertSpace")
  20. {
  21. int index = int.Parse(tokens[1]);
  22. message = message.Insert(index, " ");
  23. Console.WriteLine(message);
  24. }
  25. else if (command == "Reverse")
  26. {
  27. string substring = tokens[1];
  28. string reversedSubstring = "";
  29. if (message.Contains(substring))
  30. {
  31. int index = message.IndexOf(substring);
  32. message = message.Remove(index, substring.Length);
  33. for (int i = substring.Length - 1; i >= 0; i--)
  34. {
  35. reversedSubstring += substring[i];
  36. }
  37. message = message + reversedSubstring;
  38. Console.WriteLine(message);
  39. }
  40. else
  41. {
  42. Console.WriteLine("error");
  43. }
  44. }
  45. else if (command == "ChangeAll")
  46. {
  47. string substring = tokens[1];
  48. string replacement = tokens[2];
  49. message = message.Replace(substring, replacement);
  50. Console.WriteLine(message);
  51. }
  52. }
  53. Console.WriteLine($"You have a new text message: {message}");
  54. }
  55. }
  56.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement