ralichka

FinalExam-03.08.19-01.StringManipulator

Nov 27th, 2019
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.04 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace _01.StringManipulator
  6. {
  7.     class Program
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             string input = Console.ReadLine();
  12.             List<string> command = Console.ReadLine().Split().ToList();
  13.  
  14.             string word = command[0];
  15.             while (word != "end")
  16.             {
  17.                 if (word == "Translate")
  18.                 {
  19.                     string symbol = command[1];
  20.                     string replacement = command[2];
  21.  
  22.                     input = input.Replace(symbol, replacement);    //важно е да присвоим стойността
  23.                     Console.WriteLine(input);
  24.                 }
  25.                 else if (word == "Includes")
  26.                 {
  27.                     string word1 = command[1];
  28.                     bool result = input.Contains(word1);
  29.                     Console.WriteLine(result);
  30.                 }
  31.                 else if (word == "Start")
  32.                 {
  33.                     string word1 = command[1];
  34.                     bool result = input.StartsWith(word1);
  35.                     Console.WriteLine(result);
  36.                 }
  37.                 else if (word == "Lowercase")
  38.                 {
  39.                     input = input.ToLower();
  40.                     Console.WriteLine(input);
  41.                 }
  42.                 else if (word == "FindIndex")
  43.                 {
  44.                     string symbol = command[1];
  45.                     int lastindex = input.LastIndexOf(symbol);
  46.                     Console.WriteLine(lastindex);
  47.                 }
  48.                 else if (word == "Remove")
  49.                 {
  50.                     int start = int.Parse(command[1]);
  51.                     int count = int.Parse(command[2]);
  52.                     input = input.Remove(start, count);
  53.                     Console.WriteLine(input);
  54.                 }
  55.                 command = Console.ReadLine().Split().ToList();
  56.                 word = command[0];
  57.             }
  58.         }
  59.     }
  60. }
Advertisement
Add Comment
Please, Sign In to add comment