Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Linq;
- using System.Text;
- namespace ConsoleApp33
- {
- class Program
- {
- static void Main(string[] args)
- {
- StringBuilder username = new StringBuilder().Append(Console.ReadLine());
- string input = Console.ReadLine();
- while (input != "Registration")
- {
- string[] commands = input.Split();
- string command = commands[0];
- string temp = string.Empty;
- switch (command)
- {
- case "Letters":
- if (commands[1] == "Lower")
- {
- temp = username.ToString().ToLower();
- username.Clear();
- username.Append(temp);
- }
- else
- {
- temp = username.ToString().ToUpper();
- username.Clear();
- username.Append(temp);
- }
- break;
- case "Reverse":
- int startIndex = int.Parse(commands[1]);
- int endIndex = int.Parse(commands[2]);
- if (startIndex >= 0 && startIndex < username.Length &&
- endIndex >= 0 && endIndex < username.Length
- )
- {
- var reversed = username.ToString().Substring(startIndex, endIndex - startIndex + 1).Reverse();
- Console.WriteLine(string.Join("", reversed));
- }
- break;
- case "Substring":
- string substring = commands[1];
- string name = username.ToString();
- if (name.Contains(substring))
- {
- startIndex = name.IndexOf(substring);
- username.Remove(startIndex, substring.Length);
- }
- else
- {
- Console.WriteLine($"The username {username.ToString().Trim()} doesn't contain {substring}.");
- input = Console.ReadLine();
- continue;
- }
- break;
- case "Replace":
- char character = char.Parse(commands[1]);
- username.Replace(character, '-');
- break;
- default:
- character = char.Parse(commands[1]);
- if (username.ToString().Contains(character))
- {
- Console.WriteLine("Valid username.");
- }
- else
- {
- Console.WriteLine($"{character} must be contained in your username.");
- }
- break;
- }
- if (command == "Reverse" || command == "IsValid")
- {
- input = Console.ReadLine();
- continue;
- }
- Console.WriteLine(username.ToString().Trim());
- input = Console.ReadLine();
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment