Deserboy

Username

Aug 12th, 2019
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.65 KB | None | 0 0
  1. using System;
  2. using System.Text;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text.RegularExpressions;
  6.  
  7. namespace Playing
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             string username = Console.ReadLine();
  14.             string command = Console.ReadLine();
  15.             while (command != "Sign up")
  16.             {
  17.                 string[] tokens = command.Split().ToArray();
  18.                 if (tokens[0] == "Case")
  19.                 {
  20.                     if (tokens[1] == "lower")
  21.                     {
  22.                         username = username.ToLower();
  23.                         Console.WriteLine(username);
  24.                     }
  25.                     else if (tokens[1] == "upper")
  26.                     {
  27.                         username = username.ToUpper();
  28.                         Console.WriteLine(username);
  29.                     }
  30.                 }
  31.                 else if (tokens[0] == "Reverse")
  32.                 {
  33.                     string reversed = string.Empty;
  34.                     int startIndex = int.Parse(tokens[1]);
  35.                     int endIndex = int.Parse(tokens[2]);
  36.                     for (int i = endIndex; i > startIndex - 1; i--)
  37.                     {
  38.                         reversed += username[i];
  39.                     }
  40.                     Console.WriteLine(reversed);
  41.                 }
  42.                 else if (tokens[0] == "Cut")
  43.                 {
  44.                     if (username.Contains(tokens[1]))
  45.                     {
  46.                         int index = username.IndexOf(tokens[1]);
  47.                         username = username.Remove(index,tokens[1].Length);
  48.                         Console.WriteLine(username);
  49.                     }
  50.                     else
  51.                     {
  52.                         Console.WriteLine($"The word {username} doesn't contain {tokens[1]}.");
  53.                     }
  54.                 }
  55.                 else if (tokens[0] == "Replace")
  56.                 {
  57.                     char oldChar = char.Parse(tokens[1]);
  58.                     username = username.Replace(oldChar, '*');
  59.                     Console.WriteLine(username);
  60.                 }
  61.                 else if (tokens[0] == "Check")
  62.                 {
  63.                     if (username.Contains(tokens[1]))
  64.                     {
  65.                         Console.WriteLine("Valid");
  66.                     }
  67.                     else
  68.                     {
  69.                         Console.WriteLine($"Your username must contain {tokens[1]}.");
  70.                     }
  71.                 }
  72.                 command = Console.ReadLine();
  73.             }
  74.         }
  75.     }
  76. }
Advertisement
Add Comment
Please, Sign In to add comment