Deserboy

String Manipulator 2.0 Group 2

Aug 12th, 2019
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.55 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 text = Console.ReadLine();
  14.             string command = string.Empty;
  15.             while (command != "Done")
  16.             {
  17.                 command = Console.ReadLine();
  18.                 string[] tokens = command.Split().ToArray();
  19.                 if (tokens[0] == "Change")
  20.                 {
  21.                     text = text.Replace(tokens[1], tokens[2]);
  22.                     Console.WriteLine(text);
  23.                 }
  24.                 else if (tokens[0] == "Includes")
  25.                 {
  26.                     if (text.Contains(tokens[1]))
  27.                     {
  28.                         Console.WriteLine("True");
  29.                     }
  30.                     else
  31.                     {
  32.                         Console.WriteLine("False");
  33.                     }
  34.                 }
  35.                 else if (tokens[0] == "End")
  36.                 {
  37.                     if (text.Contains(tokens[1]))
  38.                     {
  39.                         int firstIndex = text.IndexOf(tokens[1]);
  40.                         int lastIndex = text.LastIndexOf(tokens[1]);
  41.                         if (lastIndex == text.Length - 1)
  42.                         {
  43.                             Console.WriteLine("True");
  44.                         }
  45.                         else
  46.                         {
  47.                             Console.WriteLine("False");
  48.                         }
  49.                     }
  50.                 }
  51.                 else if (tokens[0] == "Uppercase")
  52.                 {
  53.                     text = text.ToUpper();
  54.                     Console.WriteLine(text);
  55.                 }
  56.                 else if (tokens[0] == "FindIndex")
  57.                 {
  58.                     int index = text.IndexOf(tokens[1]);
  59.                     Console.WriteLine(index);
  60.                 }
  61.                 else if (tokens[0] == "Cut")
  62.                 {
  63.                     int startIndex = int.Parse(tokens[1]);
  64.                     int length = int.Parse(tokens[2]);
  65.                     string removed = string.Empty;
  66.                     for (int i = startIndex; i <= startIndex + length - 1; i++)
  67.                     {
  68.                         removed += text[i];
  69.                     }
  70.                     text = text.Remove(startIndex, length);
  71.                     Console.WriteLine(removed);
  72.                 }
  73.             }
  74.         }
  75.     }
  76. }
Advertisement
Add Comment
Please, Sign In to add comment