Advertisement
alexbancheva

Problem_1._Activation_Keys_FinalExam_04._04._20

Apr 4th, 2020
274
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.07 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. using System.Collections.Generic;
  4. using System.Text.RegularExpressions;
  5.  
  6. namespace Problem_1._Activation_Keys_FinalExam_04._04._20
  7. {
  8.     class Program
  9.     {
  10.         static void Main(string[] args)
  11.         {
  12.             string key = Console.ReadLine();
  13.             string input = "";
  14.  
  15.             while ((input = Console.ReadLine()) != "Generate")
  16.             {
  17.                 string[] splittedIn = input.Split(">>>");
  18.                 string command = splittedIn[0];
  19.  
  20.                 if (command == "Contains")
  21.                 {
  22.                     string substr = splittedIn[1];
  23.  
  24.                     if (key.Contains(substr))
  25.                     {
  26.                         Console.WriteLine($"{key} contains {substr}");
  27.                     }
  28.                     else
  29.                     {
  30.                         Console.WriteLine("Substring not found!");
  31.                     }
  32.                 }
  33.                 else if (command == "Flip")
  34.                 {
  35.                     string secCom = splittedIn[1];
  36.                     if (secCom == "Upper")
  37.                     {
  38.                         int startIndex = int.Parse(splittedIn[2]);
  39.                         int endIndex = int.Parse(splittedIn[3]);
  40.  
  41.                         if (startIndex >= 0 && endIndex >= 0 && endIndex <= key.Length)
  42.                         {
  43.                             int length = endIndex - startIndex;
  44.                             string newStr = key.Substring(startIndex, length).ToUpper();
  45.                             key = key.Replace(key.Substring(startIndex, length), newStr);
  46.                             Console.WriteLine(key);
  47.                         }
  48.                     }
  49.                     else if (secCom == "Lower")
  50.                     {
  51.                         int startIndex = int.Parse(splittedIn[2]);
  52.                         int endIndex = int.Parse(splittedIn[3]);
  53.  
  54.                         if (startIndex >= 0 && endIndex >= 0 && endIndex <= key.Length)
  55.                         {
  56.                             int length = endIndex - startIndex;
  57.                             string newStr = key.Substring(startIndex, length).ToLower();
  58.                             key = key.Replace(key.Substring(startIndex, length), newStr);
  59.                             Console.WriteLine(key);
  60.                         }
  61.                     }
  62.                 }
  63.                 else if (command == "Slice")
  64.                 {
  65.                     int startIndex = int.Parse(splittedIn[1]);
  66.                     int endIndex = int.Parse(splittedIn[2]);
  67.  
  68.                     if (startIndex >= 0 && endIndex >= 0 && endIndex <= key.Length)
  69.                     {
  70.                         int length = endIndex - startIndex;
  71.                         //string newStr = key.Substring(startIndex, length);
  72.                         key = key.Remove(startIndex, length);
  73.                         Console.WriteLine(key);
  74.                     }
  75.  
  76.                 }
  77.  
  78.             }
  79.  
  80.             Console.WriteLine($"Your activation key is: {key}");
  81.         }
  82.     }
  83. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement