alexbancheva

String Manipulator - Group 1_03.August.2019

Apr 5th, 2020
258
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.42 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text.RegularExpressions;
  5.  
  6. namespace String_Manipulator___Group_1_03.August._2019
  7. {
  8.     class Program
  9.     {
  10.         static void Main(string[] args)
  11.         {
  12.             string input = Console.ReadLine();
  13.             string command = "";
  14.  
  15.             while ((command = Console.ReadLine()) != "End")
  16.             {
  17.                 string[] splittedC = command.Split(" ");
  18.                 string newCom = splittedC[0];
  19.  
  20.                 if (newCom == "Translate")
  21.                 {
  22.                     string oldChar = splittedC[1];
  23.                     string newChar = splittedC[2];
  24.  
  25.                     input = input.Replace(oldChar, newChar);
  26.                     Console.WriteLine(input);
  27.                 }
  28.                 else if (newCom == "Includes")
  29.                 {
  30.                     string str = splittedC[1];
  31.  
  32.                     if (input.Contains(str))
  33.                     {
  34.                         Console.WriteLine(true);
  35.                     }
  36.                     else
  37.                     {
  38.                         Console.WriteLine(false);
  39.                     }
  40.                 }
  41.                 else if (newCom == "Start")
  42.                 {
  43.                     string str = splittedC[1];
  44.  
  45.                     if (input.IndexOf(str) == 0)
  46.                     {
  47.                         Console.WriteLine(true);
  48.                     }
  49.                     else
  50.                     {
  51.                         Console.WriteLine(false);
  52.                     }
  53.                 }
  54.                 else if (newCom == "Lowercase")
  55.                 {
  56.                     input = input.ToLower();
  57.                     Console.WriteLine(input);
  58.                 }
  59.                 else if (newCom == "FindIndex")
  60.                 {
  61.                     string findStr = splittedC[1];
  62.                     Console.WriteLine(input.LastIndexOf(findStr));
  63.                 }
  64.                 else if (newCom == "Remove")
  65.                 {
  66.                     int startIndex = int.Parse(splittedC[1]);
  67.                     int count = int.Parse(splittedC[2]);
  68.  
  69.                     if (startIndex >= 0 && count <= input.Length)
  70.                     {
  71.                         input = input.Remove(startIndex, count);
  72.                         Console.WriteLine(input);
  73.                     }
  74.                 }
  75.  
  76.             }
  77.         }
  78.     }
  79. }
Advertisement
Add Comment
Please, Sign In to add comment