svephoto

Nikulden's_Charity [C#]

Apr 2nd, 2021 (edited)
275
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.22 KB | None | 0 0
  1. using System;
  2.  
  3. namespace Nikulden_s_Charity
  4. {
  5.     public class Program
  6.     {
  7.         public static void Main(string[] args)
  8.         {
  9.             string message = Console.ReadLine();
  10.             int sumOfSubString = 0;
  11.            
  12.             string input = string.Empty;
  13.  
  14.             while (input != "Finish")
  15.             {
  16.                 input = Console.ReadLine();
  17.                
  18.                 string[] token = input.Split(" ", StringSplitOptions.RemoveEmptyEntries);
  19.                 string command = token[0];
  20.  
  21.                 if (command == "Replace")
  22.                 {
  23.                     string currentChar = token[1];
  24.                     string newChar = token[2];
  25.  
  26.                     if (message.Contains(currentChar))
  27.                     {
  28.                         message = message.Replace(currentChar, newChar);
  29.                     }
  30.  
  31.                     Console.WriteLine(message);
  32.                 }
  33.  
  34.                 else if (command == "Cut")
  35.                 {
  36.                     int startIdx = int.Parse(token[1]);
  37.                     int endIdx = int.Parse(token[2]);
  38.                     int length = (endIdx - startIdx) + 1;
  39.  
  40.                     if (startIdx >= 0 && endIdx < message.Length)
  41.                     {
  42.                         message = message.Remove(startIdx, length);
  43.                            
  44.                         Console.WriteLine(message);
  45.                     }
  46.                     else
  47.                     {
  48.                         Console.WriteLine("Invalid indexes!");
  49.                     }                      
  50.                 }
  51.  
  52.                 else if (command == "Make")
  53.                 {
  54.                     if (token[1] == "Upper")
  55.                     {
  56.                         message = message.ToUpper();
  57.                     }
  58.                     else
  59.                     {
  60.                         message = message.ToLower();
  61.                     }
  62.  
  63.                     Console.WriteLine(message);
  64.                 }
  65.  
  66.                 else if (command == "Check")
  67.                 {
  68.                     string str = token[1];
  69.  
  70.                     if (message.Contains(str))
  71.                     {
  72.                         Console.WriteLine($"Message contains {str}");
  73.                     }
  74.  
  75.                     else
  76.                     {
  77.                         Console.WriteLine($"Message doesn't contain {str}");
  78.                     }
  79.                 }
  80.  
  81.                 else if (command == "Sum")
  82.                 {
  83.                     int startIdx = int.Parse(token[1]);
  84.                     int endIdx = int.Parse(token[2]);
  85.                     int length = (endIdx - startIdx) + 1;
  86.  
  87.                     if (startIdx >= 0 && endIdx < message.Length)
  88.                     {
  89.                         string substr = message.Substring(startIdx, length);
  90.      
  91.                         for (int i = 0; i < substr.Length; i++)
  92.                         {
  93.                             sumOfSubString += substr[i];
  94.                         }
  95.                         Console.WriteLine(sumOfSubString);
  96.                     }
  97.                
  98.                     else
  99.                     {
  100.                         Console.WriteLine("Invalid indexes!");
  101.                     }                    
  102.                 }
  103.             }
  104.         }
  105.     }
  106. }
  107.  
Add Comment
Please, Sign In to add comment