예제 #1
0
        //4. В некотором предложении текста слова заданной длины заменить указанной подстрокой, длина которой может не совпадать с длиной слова.
        public static ISentence ReplaceWordBySubstring(ISentence sentence, int length, string newSubstring)
        {
            length       = ValidateLength(length);
            newSubstring = ValidateString(newSubstring);
            IList <ISentenceItem> substring       = new MyParser().ParseSentence(newSubstring);
            ISentence             changedSentence = sentence;

            for (int i = 0; i < sentence.Items.Count; i++)
            {
                if (changedSentence.Items[i] is Word && changedSentence.Items[i].Length == length)
                {
                    changedSentence.ReplaceWord(changedSentence.Items[i] as Word, substring);
                }
            }

            return(changedSentence);
        }