Advertisement
Chausheff

(C# Shell App Paste)

Oct 14th, 2019
395
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.60 KB | None | 0 0
  1. //Disclaimer: The creator of 'C# Shell (C# Offline Compiler)' is in no way responsible for the code posted by any user.
  2. using System;
  3. using System.IO;
  4. using System.Linq;
  5. using System.Collections.Generic;
  6.  
  7. namespace CSharp_Shell
  8. {
  9.  
  10.     public static class Program
  11.     {
  12.         public static void Main()
  13.         {
  14.             Predicate<string> match;
  15.            List<string> name = Console.ReadLine()
  16.            .Split(" ",StringSplitOptions.RemoveEmptyEntries)
  17.            .ToList();
  18.            string command;
  19.           while((command=Console.ReadLine())!="Party")
  20.           {
  21.             string[] commands=command
  22.             .Split(" ",StringSplitOptions.RemoveEmptyEntries);
  23.             switch(commands[1].ToLower())
  24.             {
  25.                 case "startswith":
  26.                 match=x=>x.StartsWith(commands[2]);
  27.                 break;
  28.                 case "Endswith":
  29.                 match=x=>x.EndsWith(commands[2]);
  30.                 break;
  31.                 case "length":
  32.                 match=x=>int.Parse(commands[2])==x.Length;
  33.                 break;
  34.                 default:
  35.                 match=null;
  36.                 break;
  37.             }
  38.             for(int i=0;i<name.Count;i++)
  39.             {
  40.               if(commands[0].ToLower()=="remove")
  41.               {
  42.                 if(match(commands[2]))
  43.                 {
  44.                     name.RemoveAt(i);
  45.                     i--;
  46.                 }
  47.               }
  48.               else
  49.               {
  50.                 if(match(commands[2]))
  51.                 {
  52.                     name.Insert(i,commands[2]);
  53.                     i++;
  54.                 }
  55.               }
  56.             }
  57.           }
  58.           Console.WriteLine(string.Join(" ",name));
  59.         }
  60.     }
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement