Advertisement
dragonbs

01. Hogwarts

Apr 2nd, 2023
183
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.71 KB | None | 0 0
  1. using System.Globalization;
  2.  
  3. string spellOgi = Console.ReadLine();
  4.  
  5. string commandOgi;
  6.  
  7. while ((commandOgi = Console.ReadLine()) != "Abracadabra")
  8. {
  9.  
  10.     string[] commArg = commandOgi.Split(' ', StringSplitOptions.RemoveEmptyEntries);
  11.     string curCommand = commArg[0];
  12.     if (curCommand == "Abjuration")
  13.     {
  14.         spellOgi = spellOgi.ToUpper();
  15.         Console.WriteLine(spellOgi);
  16.     }
  17.     else if (curCommand == "Necromancy")
  18.     {
  19.         spellOgi = spellOgi.ToLower();
  20.         Console.WriteLine(spellOgi);
  21.  
  22.     }
  23.  
  24.     else if (curCommand == "Illusion")
  25.     {
  26.         int index = int.Parse(commArg[1]);
  27.         if (index >= 0 && index < spellOgi.Length)
  28.         {
  29.             spellOgi = spellOgi.Remove(index, 1);
  30.  
  31.             string newChar = commArg[2];
  32.             spellOgi = spellOgi.Insert(index, newChar);
  33.  
  34.             Console.WriteLine("Done!");
  35.         }
  36.         else
  37.         {
  38.             Console.WriteLine("The spell was too weak.");
  39.         }
  40.  
  41.     }
  42.     else if (curCommand == "Divination")
  43.     {
  44.         string firstString = commArg[1];
  45.         string secondString = commArg[2];
  46.         if (spellOgi.Contains(firstString))
  47.         {
  48.             spellOgi = spellOgi.Replace(firstString, secondString);
  49.             Console.WriteLine(spellOgi);
  50.         }
  51.  
  52.     }
  53.     else if (curCommand == "Alteration")
  54.     {
  55.         string substring = commArg[1];
  56.         if (spellOgi.Contains(substring))
  57.         {
  58.             int indexOfSub = spellOgi.IndexOf(substring);
  59.             spellOgi = spellOgi.Remove(indexOfSub, substring.Length);
  60.             Console.WriteLine(spellOgi);
  61.         }
  62.     }
  63.     else
  64.     {
  65.         Console.WriteLine("The spell did not work!");
  66.     }
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement