Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace _01.Registration;
- internal class Program
- {
- static void Main(string[] args)
- {
- string username = Console.ReadLine();
- string input;
- while ( (input = Console.ReadLine()) != "Registration" )
- {
- string[] command = input.Split();
- if (command[0] == "Letters")
- {
- if (command[1] == "Lower")
- {
- username = username.ToLower();
- }
- else if (command[1] == "Upper")
- {
- username = username.ToUpper();
- }
- Console.WriteLine(username);
- }
- else if (command[0] == "Reverse")
- {
- int startIndex = int.Parse(command[1]);
- int endIndex = int.Parse(command[2]);
- if ( (IsValidIndex(startIndex, username.Length)) && (IsValidIndex(endIndex, username.Length)) )
- {
- string reversedSubstring = ReverseSubstring(username, startIndex, endIndex);
- Console.WriteLine(reversedSubstring);
- }
- }
- else if (command[0] == "Substring")
- {
- string substring = command[1];
- if (username.Contains(substring))
- {
- username = username.Replace(substring, "");
- Console.WriteLine(username);
- }
- else
- {
- Console.WriteLine($"The username {username} doesn't contain {substring}.");
- }
- }
- else if (command[0] == "Replace")
- {
- char charToReplace = char.Parse(command[1]);
- username = username.Replace(charToReplace, '-');
- Console.WriteLine(username);
- }
- else if (command[0] == "IsValid")
- {
- char charToCheck = char.Parse(command[1]);
- if (username.Contains(charToCheck))
- {
- Console.WriteLine("Valid username.");
- }
- else
- {
- Console.WriteLine($"{charToCheck} must be contained in your username.");
- }
- }
- }
- }
- static string ReverseSubstring(string str, int startIndex, int endIndex)
- {
- char[] charArray = new char[endIndex - startIndex + 1];
- for (int i = 0; i <= endIndex - startIndex; i++)
- {
- charArray[i] = str[startIndex + i];
- }
- Array.Reverse(charArray);
- return new string(charArray);
- }
- static bool IsValidIndex(int index, int length)
- {
- return (index >= 0) && (index < length);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement