anizko

String Manipulator

Aug 7th, 2019
207
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.22 KB | None | 0 0
  1. using System;
  2.  
  3. namespace problem03
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             string text = Console.ReadLine();
  10.             string comand = Console.ReadLine();
  11.  
  12.             while (comand != "End")
  13.             {
  14.                 string[] infoComand = comand.Split();
  15.                 if (infoComand[0] == "Translate")
  16.                 {
  17.                     char symbol = char.Parse(infoComand[1]);
  18.                     char replaceChar = char.Parse(infoComand[2]);
  19.                     text = text.Replace(symbol, replaceChar);
  20.                     Console.WriteLine(text);
  21.                 }
  22.                 else if (infoComand[0] == "Includes")
  23.                 {
  24.                     string includeString = infoComand[1];
  25.                     bool include = text.Contains(includeString);
  26.                     Console.WriteLine(include);
  27.                 }
  28.                 else if (infoComand[0] == "Start")
  29.                 {
  30.                     string startString = infoComand[1];
  31.                     bool isStart = true;
  32.                     for (int i = 0; i < startString.Length; i++)
  33.                     {
  34.                         if(startString[i]!=text[i])
  35.                         {
  36.                             isStart = false;
  37.                         }
  38.                     }
  39.                     Console.WriteLine(isStart);
  40.                 }
  41.                 else if (infoComand[0] == "Lowercase")
  42.                 {
  43.                     text = text.ToLower();
  44.                     Console.WriteLine(text);
  45.                 }
  46.                 else if (infoComand[0] == "FindIndex")
  47.                 {
  48.                     char lastIndedx = char.Parse(infoComand[1]);
  49.                     int index = text.LastIndexOf(lastIndedx);
  50.                     Console.WriteLine(index);
  51.                 }
  52.                 else if (infoComand[0] == "Remove")
  53.                 {
  54.                     int startIndex = int.Parse(infoComand[1]);
  55.                     int count = int.Parse(infoComand[2]);
  56.                     text = text.Remove(startIndex, count);
  57.                     Console.WriteLine(text);
  58.                 }
  59.                 comand = Console.ReadLine();
  60.             }
  61.         }
  62.     }
  63. }
Advertisement
Add Comment
Please, Sign In to add comment