Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Reflection.Metadata.Ecma335;
- using System.Text;
- using System.Text.RegularExpressions;
- class Program
- {
- static void Main()
- {
- string message = Console.ReadLine();
- string input;
- while ((input = Console.ReadLine()) != "Reveal")
- {
- string[] tokens = input.Split(":|:", StringSplitOptions.RemoveEmptyEntries);
- string command = tokens[0];
- if (command == "InsertSpace")
- {
- int index = int.Parse(tokens[1]);
- message = message.Insert(index, " ");
- Console.WriteLine(message);
- }
- else if (command == "Reverse")
- {
- string substring = tokens[1];
- string reversedSubstring = "";
- if (message.Contains(substring))
- {
- int index = message.IndexOf(substring);
- message = message.Remove(index, substring.Length);
- for (int i = substring.Length - 1; i >= 0; i--)
- {
- reversedSubstring += substring[i];
- }
- message = message + reversedSubstring;
- Console.WriteLine(message);
- }
- else
- {
- Console.WriteLine("error");
- }
- }
- else if (command == "ChangeAll")
- {
- string substring = tokens[1];
- string replacement = tokens[2];
- message = message.Replace(substring, replacement);
- Console.WriteLine(message);
- }
- }
- Console.WriteLine($"You have a new text message: {message}");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement