Exemplo n.º 1
0
        static void Main(string[] args)
        {
            ConsoleKeyInfo cki;
            do
            {
                Console.Clear();
                Console.WriteLine("Input string");
                string s = Console.ReadLine();
                Str s1;
                if (s==null)  s1=new Str(); else  s1 = new Str(s);
                var s2 = new Str(s1);
                Console.Clear();
                Console.WriteLine("String: " + s2);
                Console.WriteLine("Length string: " + s2.Length);

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

                Console.WriteLine("Input position and symbol, which will add");
                char x;
                int z;
                string[] tokens = Console.ReadLine().Split();
                    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;
                    }
                    s1.Add(z, x);
                    Console.WriteLine("String with extra symbol: " + s1);
                    Console.WriteLine("New length: " + s1.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;
                }
                s1.Delete(y);
                Console.WriteLine("String without extra symbol: " + s1);
                Console.WriteLine("New length: " + s1.Length);
                cki = Console.ReadKey();
            }
            while (cki.Key != ConsoleKey.Escape);
        }
Exemplo n.º 2
0
 public Str(Str s)
 {
     value = new char[s.Length];
     for (int i = 0; i < s.Length; ++i)
     {
         value[i] = s.value[i];
     }
 }
Exemplo n.º 3
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;
        }