Exemple #1
0
        public static void Main(string[] args)
        {
            // WARNING очень жуткая демонстрация
            ConsoleKeyInfo cki;

            do
            {
                Console.WriteLine("Enter first string:");
                var first = new MyString(Console.ReadLine().ToCharArray());
                Console.WriteLine("\t length: {0}", first.Length);

                Console.WriteLine("\nEnter second string:");
                var second = new MyString(Console.ReadLine().ToCharArray());
                Console.WriteLine("\t length: {0}", second.Length);

                MyString newString = first + second;
                Console.WriteLine("\nJoin two lines: {0}", newString.ToString());
                Console.WriteLine("\t length: {0}", newString.Length);

                newString = newString.Trim();
                Console.WriteLine("\nDelite separator from the beginning and end: {0}", newString.ToString());
                Console.WriteLine("\t length: {0}", newString.Length);

                char symbolOld = 'o';
                Console.WriteLine("\nFirst occurrence of a symbol '{0}' in a string \"{1}\": {2}", symbolOld, newString.ToString(), newString.IndexOf(symbolOld));

                char symbolNew  = 'n';
                var  newString1 = newString.Replace(symbolNew, symbolOld);
                Console.WriteLine(
                    "Replace the symbol '{0}' -> '{1}' in string \"{2}\": {3}",
                    symbolOld,
                    symbolNew,
                    newString,
                    newString1);

                int    position   = 0;
                string addStr     = "add substring";
                var    newString2 = newString.Insert(addStr, position);
                Console.WriteLine("\nAdd a substring \"{0}\" in string \"{1}\" from the position '{2}': {3}", addStr, newString.ToString(), position, newString2.ToString());

                var newString3 = newString.Split();
                Console.WriteLine("\nSplit a string \"{0}\":", newString.ToString());
                foreach (var e in newString3)
                {
                    Console.WriteLine("\t\"{0}\",", e.ToString());
                }

                Console.WriteLine("\nString to lower: {0}", newString.ToLower().ToString());
                Console.WriteLine("String to lower: {0}", newString.ToUpper().ToString());

                Console.WriteLine("Press the Escape (Esc) key to quit:");
                cki = Console.ReadKey();
            }while (cki.Key != ConsoleKey.Escape);
        }
Exemple #2
0
        private static void Main(string[] args)
        {
            Console.InputEncoding  = Encoding.Unicode;
            Console.OutputEncoding = Encoding.Unicode;

            MyString str = new MyString("   new");

            ShowString("Начальное состояние", str.ToString());

            str.Insert(6, new MyString("Str   "));
            ShowString("Вызов Insert(0,\'Str   \')", str.ToString());

            str.Remove(3, 3);
            ShowString("Вызов Remove(3,3)", str.ToString());

            str.Trim();
            ShowString("Вызов Trim()", str.ToString());

            str.ToLower();
            ShowString("Вызов ToLower()", str.ToString());

            str.ToUpper();
            ShowString("Вызов ToUpper()", str.ToString());

            str.Insert(0, new MyString("abcdeabcdeabcde"));
            ShowString("Вызов Insert", str.ToString());

            str.Replace('a', 'K');
            ShowString("Вызов Replace(\'a\', \'K\')", str.ToString());

            ShowString("Обращение к str[5]", str[5].ToString());
            ShowString("Вызов IndexOf(\'K\')", str.IndexOf('K').ToString());
            ShowString("Вызов LastIndexOf(\'K\')", str.LastIndexOf('K').ToString());
            ShowString("Вызов Contains(\'T\')", str.Contains('T').ToString());
            Console.ReadKey();
        }