Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Linq;
- namespace Username
- {
- class Program
- {
- static void Main(string[] args)
- {
- string text = Console.ReadLine();
- string command = Console.ReadLine();
- while (command != "Sign up")
- {
- string[] token = command.Split();
- if(token[0] == "Case")
- {
- if(token[1] == "lower")
- {
- text = text.ToLower();
- Console.WriteLine(text);
- }
- if (token[1] == "upper")
- {
- text = text.ToUpper();
- Console.WriteLine();
- }
- }
- else if(token[0] == "Reverse")
- {
- int startIndex = int.Parse(token[1]);
- int endIndex = int.Parse(token[2]);
- // !!!
- if(startIndex >= 0 && endIndex > startIndex && endIndex < text.Length)
- {
- int length = endIndex - startIndex +1 ;
- string word = text.Substring(startIndex, length);
- Console.WriteLine(String.Join("",word.Reverse()));
- }
- }
- else if(token[0]== "Cut")
- {
- string check = token[1];
- if (text.Contains(check))
- {
- text = text.Remove(text.IndexOf(check), check.Length);
- Console.WriteLine(text);
- }
- else
- {
- Console.WriteLine($"The word {text} doesn't contain {check}.");
- }
- }
- else if(token[0] == "Replace")
- {
- char currChar = char.Parse(token[1]);
- text = text.Replace(currChar, '*');
- Console.WriteLine(text);
- }
- else if(token[0] == "Check")
- {
- char charToCheck = char.Parse(token[1]);
- if (text.Contains(charToCheck))
- {
- Console.WriteLine("Valid");
- }
- else
- {
- Console.WriteLine($"Your username must contain {charToCheck}.");
- }
- }
- command = Console.ReadLine();
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement