Ejemplo n.º 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);
        }
        static void Main(string[] args)
        {
            Console.InputEncoding  = Encoding.Unicode;
            Console.OutputEncoding = Encoding.Unicode;

            MyString str1 = new MyString();
            MyString str2 = new MyString("Строка1");
            MyString str3 = new MyString("Строка2");

            str1 = "Строка";
            str2 = str2 + str3;

            Console.WriteLine("Исходные строки:");
            Console.WriteLine("str1 = {0}", str1.ToString());
            Console.WriteLine("str2 = {0}", str2.ToString());
            Console.WriteLine("str3 = {0}", str3.ToString());

            Console.WriteLine("\nТиповые операции класса MyString:");
            Console.WriteLine("str2.Contains('к') = {0}", str3.Contains('к'));
            Console.WriteLine("str2.EndWith('2') = {0}", str3.EndWith('2'));
            Console.WriteLine("str3.IndexOf('р') = {0}", str3.IndexOf('р'));
            Console.WriteLine("str1.Insert(0,\"Новая \") = {0}", str1.Insert(0, "Новая "));
            Console.WriteLine("str1.LastIndexOf('а') = {0}", str1.LastIndexOf('а'));
            Console.WriteLine("str1.Length = {0}", str1.Length);
            Console.WriteLine("str2.Remove(3) = {0}", str2.Remove(3));
            Console.WriteLine("str3.Remove(2, 2) = {0}", str3.Remove(2, 2));
            Console.WriteLine("str1.Replace('а', 'б') = {0}", str1.Replace('а', 'б'));
            Console.WriteLine("str1.StartWith('б') = {0}", str1.StartWith('б'));
            Console.WriteLine("str1.Substring(4) = {0}", str1.Substring(4));
            Console.WriteLine("str1.Substring(1, 3) = {0}", str1.Substring(1, 3));
            Console.WriteLine("str1.ToLower() = {0}", str1.ToLower());
            Console.WriteLine("str2.ToUpper() = {0}", str2.ToUpper());
            Console.ReadKey();
        }
Ejemplo n.º 3
0
        static void Main(string[] args)
        {
            MyString string1 = new MyString("qerwter");
            MyString string2 = new MyString("er");
            MyString string3 = string1 - string2;

            Console.WriteLine(string3.ToString());
            bool compare = string1 == string2;

            Console.Read();
        }
Ejemplo n.º 4
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();
        }