Пример #1
0
        static void Main(string[] args)
        {
            ConsoleKeyInfo cki;
            do
            {
                Console.Clear();
                Console.WriteLine("Input string");
                string s = Console.ReadLine();
                var s1 = new Str(s);
                var s2 = new Str(s1);
                Console.Clear();
                Console.WriteLine("String: " + s2);
                Console.WriteLine("Length string: " + s2.Length);

                var q = Str.DeleteSpace(s1);
                Console.WriteLine("Same without extraspaces: " + q);
                Console.WriteLine("New length: " + q.Length);

                Console.WriteLine("Input position and symbol, which will add");
                string[] tokens = Console.ReadLine().Split();
                char x;
                int z;
                if (!(int.TryParse(tokens[0], out z)))
                {
                    Console.WriteLine("Error. Incorrect value");
                    return;
                }
                else if (!(char.TryParse(tokens[1], out x)))
                {
                    Console.WriteLine("Error. Incorrect value");
                    return;
                }
                var q2 = s1.Add(z,x);
                Console.WriteLine("String with extra symbol: " + q2);
                Console.WriteLine("New length: " + q2.Length);

                Console.WriteLine("Input number symbol, which will delete");
                tokens = Console.ReadLine().Split();
                int y;
                if (!(int.TryParse(tokens[0], out y)))
                {
                    Console.WriteLine("Error. Incorrect value");
                    return;
                }
                var q3 = s1.Delete(y);
                Console.WriteLine("String without extra symbol: " + q3);
                Console.WriteLine("New length: " + q3.Length);
                cki = Console.ReadKey();
            }
            while (cki.Key != ConsoleKey.Escape);
        }
Пример #2
0
        public static Str DeleteSpace(Str s)
        {
            while (s[0] == ' ')
            {
                s = s.Delete(0);
            }
            while (s[s.Length - 1] == ' ')
            {
                s = s.Delete(s.Length - 1);
            }

            for (int i = 0; i < s.Length - 1; i++)
            {
                if (s[i] == ' ' && s[i + 1] == ' ')
                {
                    while (s[i + 1] == ' ')
                    {
                        s = s.Delete(i+1);
                    }
                }
            }
            return s;
        }