knoteva

01. String Manipulator - Group 2

Aug 5th, 2019
91
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. using System.Linq;
  3.  
  4. namespace _01._Problem
  5. {
  6.     class Program
  7.     {
  8.         static void Main(string[] args)
  9.         {
  10.             string str = Console.ReadLine();
  11.             string line = string.Empty;
  12.  
  13.             while ((line = Console.ReadLine())!= "Done")
  14.             {
  15.                 string command = line.Split(" ")[0];
  16.  
  17.                 if (command == "Change")
  18.                 {
  19.                     var ch = line.Split(" ")[1].ToCharArray();
  20.                     var repl = line.Split(" ")[2];
  21.                     str = new string(str.Select(r => r == ch[0] ? (char)(repl[0]) : r).ToArray());
  22.                     Console.WriteLine(str);
  23.                 }
  24.                 else if (command == "Includes")
  25.                 {
  26.                     var isIncluded = line.Split(" ")[1];
  27.                     if (str.Contains(isIncluded))
  28.                     {
  29.                         Console.WriteLine("True");
  30.                     }
  31.                     else
  32.                     {
  33.                         Console.WriteLine("False");
  34.                     }
  35.                 }
  36.                 else if (command == "End")
  37.                 {
  38.                     var endsWith = line.Split(" ")[1];
  39.                     if (str.EndsWith(endsWith))
  40.                     {
  41.                         Console.WriteLine("True");
  42.                     }
  43.                     else
  44.                     {
  45.                         Console.WriteLine("False");
  46.                     }
  47.                 }
  48.                 else if (command == "Uppercase")
  49.                 {
  50.                     str = str.ToUpper();
  51.                     Console.WriteLine(str);
  52.                 }
  53.                 else if (command == "FindIndex")
  54.                 {
  55.                     var ch = line.Split(" ")[1].ToCharArray();
  56.                     Console.WriteLine(str.IndexOf(ch[0]));
  57.                 }
  58.                 else if (command == "Cut")
  59.                 {
  60.                     int startIndex = int.Parse(line.Split(" ")[1]);
  61.                     int length = int.Parse(line.Split(" ")[2]);
  62.                     str = str.Substring(startIndex, length);
  63.                     Console.WriteLine(str);
  64.                 }
  65.             }
  66.         }
  67.     }
  68. }
Add Comment
Please, Sign In to add comment