Advertisement
KMiteva

String Manipulator - Group 1 - 90/100

Apr 1st, 2020
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.55 KB | None | 0 0
  1. using System;
  2. using System.Text;
  3.  
  4. namespace Messages_Manager
  5. {
  6.     class Program
  7.     {
  8.         static void Main(string[] args)
  9.         {
  10.             string input = Console.ReadLine();
  11.  
  12.             string command = Console.ReadLine();
  13.  
  14.             while (command != "End")
  15.             {
  16.                 var split = command.Split();
  17.                 string action = split[0];
  18.                
  19.                 switch (action)
  20.                 {
  21.                     case "Translate":
  22.                         char replace = char.Parse(split[1]);
  23.                         char replacement = char.Parse(split[2]);
  24.                         input = input.Replace(replace, replacement);
  25.                         Console.WriteLine(input);
  26.                         break;
  27.                     case "Includes":
  28.                         string isInclude = split[1];
  29.                         if (input.Contains(isInclude))
  30.                         {
  31.                             Console.WriteLine("True");
  32.                         }
  33.                         else
  34.                         {
  35.                             Console.WriteLine("False");
  36.                         }
  37.                         break;
  38.                     case "Start":
  39.                         string start = split[1];
  40.                         if (input.StartsWith(start))
  41.                         {
  42.                             Console.WriteLine("True");
  43.                         }
  44.                         else
  45.                         {
  46.                             Console.WriteLine("False");
  47.                         }
  48.                         break;
  49.                     case "Lowercase":
  50.                         input = input.ToLower();
  51.                         Console.WriteLine(input);
  52.                         break;
  53.                     case "FindIndex":
  54.                         int lastIndex = input.LastIndexOf(split[1]);
  55.                         Console.WriteLine(lastIndex);
  56.                         break;
  57.                     case "Remove":
  58.                         int startIndex = int.Parse(split[1]);
  59.                         int count = int.Parse(split[2]);
  60.                        
  61.                         if (startIndex >= 0 && count > 0 && startIndex + count <= input.Length)
  62.                         {
  63.                             input = input.Remove(startIndex, startIndex + count);
  64.                             Console.WriteLine(input);
  65.                         }
  66.                         break;
  67.                 }
  68.                 command = Console.ReadLine();
  69.             }
  70.         }
  71.     }
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement