예제 #1
0
        private static Dictionary <CustomString, int> CalculateStringsFrequencies(CustomString text, bool dependOnRegister, params char[] separators)
        {
            if (!dependOnRegister)
            {
                text = text.ReplaceByDelegate(c => char.ToLower(c));
            }

            Dictionary <CustomString, int> result = new Dictionary <CustomString, int>();

            List <char> currentStringSymbols = new List <char>();

            for (int i = 0; i < text.Length; i++)
            {
                if (separators.Contains(text[i]))
                {
                    CustomString str = CustomString.CreateInstance(currentStringSymbols.ToArray());

                    currentStringSymbols.Clear();

                    AddStringToFrequencies(result, str);

                    continue;
                }

                currentStringSymbols.Add(text[i]);
            }

            AddStringToFrequencies(result, CustomString.CreateInstance(currentStringSymbols.ToArray()));

            return(result);
        }
예제 #2
0
        private static void WriteCustomMethodsExamples()
        {
            Console.WriteLine("Examples of custom methods.");

            CustomString str = CustomString.CreateInstance("HeLLo wOrld".ToCharArray());

            Console.WriteLine($"{nameof(str)} = CreateInstance(\"{str}\")");

            Console.WriteLine($"str.RemoveByPredicate(c => char.IsUpper(c)) => {str.RemoveByPredicate(c => char.IsUpper(c))}");
            Console.WriteLine($"str.RemoveByPredicate(c => c == 'L') => {str.RemoveByPredicate(c => c == 'L')}");
            Console.WriteLine($"str.ReplaceByDelegate(c => char.ToLower(c)) => {str.ReplaceByDelegate(c => char.ToLower(c))}");
            Console.WriteLine($"str.ReplaceByDelegate(c => char.ToLower(c) == 'l' ? '1' : c)) => {str.ReplaceByDelegate(c => char.ToLower(c) == 'l' ? '1' : c)}");

            WriteSeparatorStringsAndAwaitMessage();
        }