Пример #1
0
        static void Main(string[] args)
        {
            string fileName = "../../../../../bigtext.txt";

            try
            {
                Message message = new Message(File.ReadAllText(fileName, Encoding.UTF8));
                message.task05a(3);

                UseMethods.Print("------------");
                UseMethods.Print(message.task05b('t'));

                UseMethods.Print("------------");
                UseMethods.Print("Find max words:");
                message.task05c(true);

                UseMethods.Print("------------");
                UseMethods.Print("Use StringBuilder Class:");
                message.task05d();

                UseMethods.Print("------------");
                foreach (var item in message.task05g())
                {
                    Console.WriteLine(item);
                }
            }
            catch (Exception ex)
            {
                UseMethods.Print($"File {fileName} not found.");
                UseMethods.Print($"{ex}");
            }
        }
Пример #2
0
        /*
         * - в) Найти самое длинное слово сообщения.
         */
        public List <string> task05c(bool printElements = false)
        {
            int           max     = 0;
            List <string> retList = new List <string>();

            string[] a = message.Split(delimiters, StringSplitOptions.None);

            foreach (string element in a)
            {
                if (element.Length > max)
                {
                    max = element.Length;
                }
            }

            foreach (string element in a)
            {
                if (element.Length == max)
                {
                    if (retList.Contains(element) != true)
                    {
                        retList.Add(element);
                        if (printElements)
                        {
                            UseMethods.Print($"'{element}'");
                        }
                    }
                }
            }

            return(retList);
        }
Пример #3
0
        /*
         * - г) Сформировать строку с помощью StringBuilder из самых длинных слов сообщения.
         */
        public void task05d()
        {
            int max = 0;

            string[]      a    = message.Split(delimiters, StringSplitOptions.None);
            StringBuilder bStr = new StringBuilder("");

            foreach (string element in a)
            {
                if (element.Length > max)
                {
                    max = element.Length;
                }
            }

            foreach (string element in a)
            {
                if (element.Length == max)
                {
                    bStr.Append(element + " ");
                }
            }

            UseMethods.Print(bStr);
        }
Пример #4
0
        public bool CheckLoginRegEx()
        {
            Regex regex = new Regex(@"^[a-zA-Z][0-9a-zA-Z]{2,9}$");

            do
            {
                username = UseMethods.GetValue("Введите логин: ");
            } while (!regex.IsMatch(username));

            return(true);
        }
Пример #5
0
        /*
         * - а) Вывести только те слова сообщения, которые содержат не более n букв.
         */
        public void task05a(int n)
        {
            string[] a = message.Split(delimiters, StringSplitOptions.None);

            foreach (string element in a)
            {
                if (element.Length <= n && element.Length > 0 && Char.IsLetterOrDigit(element[0]))
                {
                    UseMethods.Print(element);
                }
            }
        }
Пример #6
0
        static void Main(string[] args)
        {
            CheckLogin loginName = new CheckLogin();

            UseMethods.Print("Simpe check.");
            if (loginName.CheckLoginSimple())
            {
                UseMethods.Print($"Login name \x1b[1;12m'{loginName.GetUsername}'\x1b[0m is correct.");
            }

            UseMethods.Print("Regex check.");
            if (loginName.CheckLoginRegEx())
            {
                UseMethods.Print($"Login name \x1b[1;12m'{loginName.GetUsername}'\x1b[0m is correct.");
            }
        }
Пример #7
0
        public bool CheckLoginSimple()
        {
            bool letterOrDigits = true;

            do
            {
                username       = UseMethods.GetValue("Введите логин: ");
                letterOrDigits = true;
                foreach (char c in username)
                {
                    if (!char.IsLetterOrDigit(c))
                    {
                        letterOrDigits = false;
                    }
                }
            } while (username.Length < 2 || username.Length > 10 || Char.IsDigit(username[0]) || !letterOrDigits);

            return(true);
        }
Пример #8
0
        static void Main(string[] args)
        {
            string str1 = "abcd";
            string str2 = "badc";

            if (IsAnagram(str1, str2))
            {
                UseMethods.Print($"Строка {str1}  явлеяет анаграммой строки {str2}.");
            }
            else
            {
                UseMethods.Print($"Строка {str1}  не явлеяет анаграммой  строки {str2}.");
            }

            if (IsAnagramV2(str1, str2))
            {
                UseMethods.Print($"Строка {str1}  явлеяет анаграммой строки {str2}.");
            }
            else
            {
                UseMethods.Print($"Строка {str1}  не явлеяет анаграммой  строки {str2}.");
            }
        }