Пример #1
0
        private List <string> GetSplittedString()
        {
            if (!ContentText.ToLower().Contains(HighlightText.ToLower()))
            {
                return new List <string>()
                       {
                           ContentText
                       }
            }
            ;

            int           startIndex    = ContentText.IndexOf(HighlightText, StringComparison.OrdinalIgnoreCase);
            List <string> splittedTexts = new List <string>();
            string        matchedText   = ContentText.Substring(startIndex, HighlightText.Length);
            string        startText     = startIndex > 0 ? ContentText.Substring(0, startIndex) : string.Empty;
            string        lastText      = ContentText.Substring(startIndex + HighlightText.Length);

            if (!string.IsNullOrEmpty(startText))
            {
                splittedTexts.Add(startText);
            }

            if (!string.IsNullOrEmpty(matchedText))
            {
                splittedTexts.Add(matchedText);
            }

            if (!string.IsNullOrEmpty(lastText))
            {
                splittedTexts.Add(lastText);
            }

            return(splittedTexts);
        }
    }