joro_thexfiles

String Manipulator

Aug 2nd, 2019
181
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.83 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4.  
  5. namespace String_Manipulator
  6. {
  7.     class Program
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             string sb = "";
  12.  
  13.             while (true)
  14.             {
  15.                 string text = Console.ReadLine();
  16.  
  17.                 if (text == "End")
  18.                 {
  19.                     break;
  20.                 }
  21.                 else
  22.                 {
  23.                     if (text == "Print")
  24.                     {
  25.                         Console.WriteLine(sb);
  26.                     }
  27.                     else
  28.                     {
  29.                         string[] data = text.Split(' ');
  30.  
  31.                         string command = data[0];
  32.  
  33.                         if (command == "Add")
  34.                         {
  35.                             string currentString = data[1];
  36.                             sb += currentString;
  37.                         }
  38.                         else if (command == "Upgrade")
  39.                         {
  40.                             char currentSymbol = char.Parse(data[1]);
  41.  
  42.                             sb = sb.Replace(currentSymbol, (char)(currentSymbol + 1));
  43.  
  44.                         }
  45.                         else if (command == "Index")
  46.                         {
  47.                             char currentSymbol = char.Parse(data[1]);
  48.  
  49.                             bool isThereLookingSymbol = false;
  50.  
  51.                             for (int i = 0; i < sb.Length; i++)
  52.                             {
  53.                                 char currentChar = sb[i];
  54.  
  55.                                 if (currentSymbol == currentChar)
  56.                                 {
  57.                                     Console.Write($"{i} ");
  58.                                     isThereLookingSymbol = true;
  59.                                 }
  60.                             }
  61.  
  62.                             Console.WriteLine();
  63.  
  64.                             if (isThereLookingSymbol == false)
  65.                             {
  66.                                 Console.WriteLine("None");
  67.                             }
  68.                         }
  69.                         else if (command == "Remove")
  70.                         {
  71.                             string stringForRemoving = data[1];
  72.  
  73.                             while (true)
  74.                             {
  75.                                 if (sb.Contains(stringForRemoving))
  76.                                 {
  77.                                    sb = sb.Replace(stringForRemoving, "");
  78.                                 }
  79.                                 else
  80.                                 {
  81.                                     break;
  82.                                 }
  83.                             }
  84.                         }
  85.                     }
  86.                 }
  87.             }
  88.         }
  89.     }
  90. }
Advertisement
Add Comment
Please, Sign In to add comment