public static void Main()
    {
        var stringEditor = new StringEditor();

        stringEditor.Login("pesho");
        stringEditor.Prepend("pesho", "stringexample");
        stringEditor.Delete("pesho", 3, 6);
        stringEditor.Insert("pesho", 3, "asdassdaasd");
        Console.WriteLine(stringEditor.Print("pesho"));
    }
예제 #2
0
    private static void Test()
    {
        var stringEditor = new StringEditor();
        var currentUser  = "******";

        stringEditor.Login(currentUser);
        stringEditor.Login("Gosho");
        stringEditor.Login("Pavel");
        stringEditor.Login("Asen");
        stringEditor.Prepend(currentUser, "DEF");
        stringEditor.Prepend(currentUser, " ");
        stringEditor.Prepend(currentUser, "abc");
        stringEditor.Prepend(currentUser, " ");
        stringEditor.Prepend(currentUser, "ZDF");
        Console.WriteLine(stringEditor.Print(currentUser));

        stringEditor.Delete(currentUser, 1, 2);

        Console.WriteLine(stringEditor.Print(currentUser));

        stringEditor.Insert(currentUser, 1, "_NEW STRING_");

        Console.WriteLine(stringEditor.Print(currentUser));

        Console.WriteLine(stringEditor.Length(currentUser));

        stringEditor.Substring(currentUser, 1, 12);

        Console.WriteLine(stringEditor.Print(currentUser));

        stringEditor.Undo(currentUser);

        Console.WriteLine(stringEditor.Print(currentUser));

        stringEditor.Clear(currentUser);

        Console.WriteLine(stringEditor.Print(currentUser));

        foreach (var user in stringEditor.Users("P"))
        {
            Console.WriteLine(user);
        }
    }
    public static void Main()
    {
        string       command    = string.Empty;
        StringEditor textEditor = new StringEditor();

        while ((command = Console.ReadLine()) != "end")
        {
            string[] inputs = command.Split();

            try
            {
                if (inputs[0] == "login")
                {
                    textEditor.Login(inputs[1]);
                    continue;
                }

                if (inputs[0] == "users")
                {
                    if (inputs.Length > 1)
                    {
                        foreach (string user in textEditor.Users(inputs[1]))
                        {
                            Console.WriteLine(user);
                        }
                    }
                    else
                    {
                        foreach (string user in textEditor.Users())
                        {
                            Console.WriteLine(user);
                        }
                    }

                    continue;
                }

                if (inputs[0] == "logout")
                {
                    textEditor.Logout(inputs[1]);
                    continue;
                }

                if (inputs[1] == "prepend")
                {
                    string[] stringToPrepend = command.Split(new char[] { '"' }, StringSplitOptions.RemoveEmptyEntries).Skip(1).Take(1).ToArray();
                    textEditor.Prepend(inputs[0], stringToPrepend[0]);
                    continue;
                }

                if (inputs[1] == "print" && textEditor.userStrings.ContainsKey(inputs[0]))
                {
                    Console.WriteLine(textEditor.Print(inputs[0]));
                    continue;
                }

                if (inputs[1] == "delete" && textEditor.userStrings.ContainsKey(inputs[0]))
                {
                    textEditor.Delete(inputs[0], int.Parse(inputs[2]), int.Parse(inputs[3]));
                    continue;
                }

                if (inputs[1] == "delete" && textEditor.userStrings.ContainsKey(inputs[0]))
                {
                    textEditor.Delete(inputs[0], int.Parse(inputs[2]), int.Parse(inputs[3]));
                    continue;
                }

                if (inputs[1] == "insert" && textEditor.userStrings.ContainsKey(inputs[0]))
                {
                    string[] stringToInsert = command.Split(new char[] { '"' }, StringSplitOptions.RemoveEmptyEntries).Skip(1).Take(1).ToArray();
                    textEditor.Insert(inputs[0], int.Parse(inputs[2]), stringToInsert[0]);
                    continue;
                }

                if (inputs[1] == "length" && textEditor.userStrings.ContainsKey(inputs[0]))
                {
                    Console.WriteLine(textEditor.Length(inputs[0]));
                    continue;
                }

                if (inputs[1] == "clear" && textEditor.userStrings.ContainsKey(inputs[0]))
                {
                    textEditor.Clear(inputs[0]);
                    continue;
                }

                if (inputs[1] == "substring" && textEditor.userStrings.ContainsKey(inputs[0]))
                {
                    textEditor.Substring(inputs[0], int.Parse(inputs[2]), int.Parse(inputs[3]));
                    continue;
                }
            }
            catch
            {
            }
        }
    }
예제 #4
0
    public static void Main()
    {
        var textEditor = new StringEditor();

        while (true)
        {
            var input    = Console.ReadLine();
            var text     = input.Split('"');
            var commands = input.Split();
            if (commands[0] == "end")
            {
                break;
            }

            switch (commands[0])
            {
            case "login":
                textEditor.Login(commands[1]);
                break;

            case "logout":
                textEditor.Logout(commands[1]);
                break;

            case "users":
                if (commands.Length > 1)
                {
                    foreach (var user in textEditor.Users(commands[1]))
                    {
                        Console.WriteLine(user);
                    }
                }
                else
                {
                    foreach (var user in textEditor.Users())
                    {
                        Console.WriteLine(user);
                    }
                }
                break;

            default:
                var name    = commands[0];
                var command = commands[1];

                switch (command)
                {
                case "insert":
                    var index = int.Parse(commands[2]);
                    textEditor.Insert(name, index, text[1]);
                    break;

                case "prepend":
                    textEditor.Prepend(name, text[1]);
                    break;

                case "substring":
                    var startIndex = int.Parse(commands[2]);
                    var length     = int.Parse(commands[3]);
                    textEditor.Substring(name, startIndex, length);
                    break;

                case "delete":
                    var startIndexD = int.Parse(commands[2]);
                    var lengthD     = int.Parse(commands[3]);
                    textEditor.Delete(name, startIndexD, lengthD);
                    break;

                case "clear":
                    textEditor.Clear(name);
                    break;

                case "length":
                    Console.WriteLine(textEditor.Length(name));
                    break;

                case "print":
                    try
                    {
                        Console.WriteLine(textEditor.Print(name));
                    }
                    catch (Exception)
                    {
                    }
                    break;

                case "undo":
                    textEditor.Undo(name);
                    break;

                default: throw new InvalidOperationException();
                }
                break;
            }
        }
    }