Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Text;
- namespace SecretChat
- {
- class Program
- {
- static void Main(string[] args)
- {
- string concealedMessage = Console.ReadLine();
- StringBuilder sbMessage = new StringBuilder(concealedMessage);
- string command = string.Empty;
- while ((command = Console.ReadLine()) != "Reveal")
- {
- string[] commandArray = command.Split(":|:");
- if (commandArray[0] == "InsertSpace")
- {
- int index = int.Parse(commandArray[1]);
- sbMessage.Insert(index, " ");
- Console.WriteLine(sbMessage);
- }
- else if (commandArray[0] == "Reverse")
- {
- string substring = commandArray[1];
- if (sbMessage.ToString().Contains(substring))
- {
- int startIndex = sbMessage.ToString().IndexOf(substring);
- int substringLength = substring.Length;
- sbMessage.Remove(startIndex, substringLength);
- string reverseMessage = string.Empty;
- for (int i = substring.Length - 1; i >= 0; i--)
- {
- reverseMessage += substring[i];
- }
- sbMessage.Append(reverseMessage);
- Console.WriteLine(sbMessage);
- }
- else
- {
- Console.WriteLine("error");
- }
- }
- else if (commandArray[0] == "ChangeAll")
- {
- string substring = commandArray[1];
- string replacement = commandArray[2];
- if (sbMessage.ToString().Contains(substring))
- {
- sbMessage.Replace(substring, replacement);
- Console.WriteLine(sbMessage);
- }
- }
- }
- Console.WriteLine($"You have a new text message: {sbMessage}");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement